FromQuery. FromHeader. FromForm. FromRoute. FromServices. FromBody.
These are all attributes that can be added to an action parameter in an ASP.NET Core controller. These work regardless of whether you are building an ASP.NET Core Web API or MVC app.
The code sample will give you examples of how to use these attributes in an ASP.NET Core web app as part of a controller's action. They also include a sample of using the
Name property which are included in a number of these attributes.
In-addition, we'll give you a Postman import script so you can execute these endpoints.
Watch our video to see the controllers are included, how the functionality works and how we tested it in Postman.
As well as that, you can read the tutorial so you can understand how each attribute works and when to use them.
This is the software that will need to be installed onto your machine.
These are the steps to get the application working.
You are now ready to go.
RoundTheCode.FromAttributes.sln in Visual Studio. The start up project should be set to
RoundTheCode.FromAttributes.Web which is the ASP.NET Core web app.
Start the application, and your browser should open up to
https://localhost:9906 with the Swagger documentation.
At this point, you'll be able to execute each endpoint in Postman.
Postman folder of the ZIP file, there are two Postman import scripts. Assuming you are using a later version of Postman, you should be able to use the
RoundTheCode.FromAttributes.postman_collection_2.1.json file to import the endpoints to Postman.
In Postman, click on the menu icon in the top-left hand corner of the screen and go to File and Import.
Click on the files link and find the Postman import file.
The endpoints should now be imported into Postman. With your ASP.NET Core web app running, you should be able to execute each endpoint.