filmov
tv
FromQuery? FromBody? What are these ASP.NET Core Web API attributes?
Показать описание
FromQuery and FromBody are some of the attributes that can be placed on a parameter in an controller's action.
These attributes can be used in an ASP.NET Core Web API or MVC app and it helps to bind a parameter against a value which is part of the HTTP request.
The attributes we will look at are:
► FromQuery - Binds a parameter from the query string
► FromHeader - Binds a parameter from the header
► FromForm - Binds a parameter from a form field if the multipart/form-data or x-www-url-encoded content type is used in the request
► FromRoute - Binds a parameter from a route attribute
► FromBody - Binds a parameter when the application/json content type is used in the request and JSON formatted content is part of the body
There is also a FromServices attribute. However, this binds an instance that has been added to the IoC container as part of dependency injection.
This video will show you a C# example of each one and how to test it using Postman.
In-addition, we'll have a look at the ApiController attribute and how the features and behaviour of a controller are changed with this attribute.
💻 Download the code example for this tutorial💻
📖 Learn .NET and C# with our online courses 📖
► More information:
► Chapters
0:00 The ASP.NET Core attributes we will use
0:19 Learn with .NET courses
0:29 Create controller
1:12 FromQuery attribute
3:01 FromHeader attribute
5:09 FromForm attribute
7:11 FromRoute attribute
9:12 FromServices attribute
12:23 FromBody attribute
14:57 What's included with the code sample
#webapi #mvc #dotnet
These attributes can be used in an ASP.NET Core Web API or MVC app and it helps to bind a parameter against a value which is part of the HTTP request.
The attributes we will look at are:
► FromQuery - Binds a parameter from the query string
► FromHeader - Binds a parameter from the header
► FromForm - Binds a parameter from a form field if the multipart/form-data or x-www-url-encoded content type is used in the request
► FromRoute - Binds a parameter from a route attribute
► FromBody - Binds a parameter when the application/json content type is used in the request and JSON formatted content is part of the body
There is also a FromServices attribute. However, this binds an instance that has been added to the IoC container as part of dependency injection.
This video will show you a C# example of each one and how to test it using Postman.
In-addition, we'll have a look at the ApiController attribute and how the features and behaviour of a controller are changed with this attribute.
💻 Download the code example for this tutorial💻
📖 Learn .NET and C# with our online courses 📖
► More information:
► Chapters
0:00 The ASP.NET Core attributes we will use
0:19 Learn with .NET courses
0:29 Create controller
1:12 FromQuery attribute
3:01 FromHeader attribute
5:09 FromForm attribute
7:11 FromRoute attribute
9:12 FromServices attribute
12:23 FromBody attribute
14:57 What's included with the code sample
#webapi #mvc #dotnet
Комментарии