- 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.
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.
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.
https://localhost:9906 with the Swagger documentation.
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.
How to import a Postman script
Click on the files link and find the Postman import file.
Select a Postman file to import
The endpoints should now be imported into Postman. With your ASP.NET Core web app running, you should be able to execute each endpoint.
Imported ASP.NET Core endpoints in Postman
Related code examples
A FromBody and FromQuery sample in ASP.NET Core Web API
An ASP.NET Core example of using the FromBody and FromQuery attribute. Handy if your request is null, or getting a 415 error.