- Home
- .NET code examples
- FromQuery and other ASP.NET Core Web API attributes
FromQuery and other ASP.NET Core Web API attributes
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.
What's included?
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.
C# coding challenges
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.
Software
This is the software that will need to be installed onto your machine.
- Visual Studio 2022. Version 17.5.4 or above. It will work with the free community version.
- .NET 7 SDK. Version 7.0.5 or above.
Get the application working
These are the steps to get the application working.
- Fill out the code example form. We will send you an email where you can download the code example.
You are now ready to go.
Open the project in Visual Studio
Open up 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.
Import Postman endpoints
Inside the 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.