Check out this code sample.
1 | [] |
[HttpGet] is an annotation that tells the compiler that the method is a method that can be called via an HTTP GET request.
There’s a few other method related annotations [HttpPost], [HttpPut], [HttpDelete]. These are used to tell the compiler that the method is a method that can be called via an HTTP POST, PUT, or DELETE request. This is somewhat of a tricky concept, but it’s important to understand. Suffice to say browsers can send HTTP GET, POST, PUT, and DELETE requests to API’s. Programs like Postman can also send HTTP GET, POST, PUT, and DELETE requests to API’s.
1 | [] |
You can configure the Get (post, put, and delete statements) so that they accept multiple parameters. In this particular example, the method GetOne() accepts a single parameter called id. The id parameter is a long data type. The id parameter is passed in as a parameter to the method. The id parameter is used to retrieve a record from the database.
You could enter a command like this in a browser: http://localhost:5000/api/v1/reconciles/1 and it will return a record from the database.
To pass 2 properties to a method, you can use the following syntax:
1 | [] |
In this case 2 arguments are expected. They are pulled out of the URL and passed to the GetByBankAccountNdStartDate() method. The first argument going into the bankAccountId parameter and the second argument going into the startDate parameter.