Section 5: Adding a HTTP GET method (Restful API in ASP .Net Core)

 Section 5: Adding a HTTP GET method


Introduction:


In Section 4, we have added a controller. When Controller receives a request, the request needs to be routed. What I mean is that a HTTP request could be of various types, such as GET, POST, PUT and DELETE. This represents the CRUD operations.

  • GET represents the READing records.
  • POST represents the CREATing records.
  • PUT represents the UPDATing a record.
  • DELETE represents the DELETing a record.

In this section, let us see how we can Read a record using HTTP's GET method.


To add a HTTP's GET method, 

  • Create a method, say Get(). This method should have a Attribute [HttpGet]. This says the compiler that this method is for HTTP's GET method. 
  • Create a List of Movies to be returned for the controller. We have to store the data in the Database; however, let us, for now, create a static list and return it. Let us store the data in the DB later.

Please follow the steps as below:






How to test this?


To Test, we have to use Postman tool. Please google Postman and install the latest version. 

After installing Postman, we have to create a workspace and create a new Get Request. 

Let's see this as below: