title: How to call api from ASP.NET razor view
body: <p>Just as stated above, I am not sure how to call an <code>API</code>.<br>
  I have done it using fetch in the example below:</p>
  
  <pre><code>fetch("https://localhost:5001/api/patients/add", {
    method: "POST",
    mode: "cors",
    cache: "no-cache",
    headers: { "Content-Type": "application/json" },
    body: postBody
  });}
  </code></pre>
  
  <p>But it seems there is a different way of doing things in <strong>Razor view</strong>.<br>
  Below is what I have in my <code>API</code>:</p>
  
  <pre><code>    // GET: api/Patients/5
      [HttpGet("{id}")]
      public async Task&lt;ActionResult&lt;Patient&gt;&gt; GetPatient(int id)
      {
          var patient = await _context.Patient.FindAsync(id);
  
          if (patient == null)
          {
              return NotFound();
          }
  
          return patient;
      }
  </code></pre>
  
  <p>It's just the <code>GET</code> made when creating an <code>API</code> in <code>Visual Studio</code>.</p>