There are 4 series of blogs in front
(i) pits in the ASP. NET Web API-"Cannot find HTTP resource matching request URI"
(ii) pits in the ASP. NET Web API-"parameters in an HTTP GET request"
(iii) pits in the ASP. NET Web API-"parameters in an HTTP POST request"
(iv) pits in the ASP. NET Web API-"Return value of API"
The above is mainly for the ASP. NET Web API RPC style, get,post request parameter, and Webapi return value and so on.
This article focuses on the. NET CORE WEB API (restful style)
We all know that. NET core out for a while, the garden of various introduction of life, cross-platform deployment, Docker deployment, command line blog A lot, I will not repeat, and these I have done.
The topic of this article is about WEBAPI, but only for. NET core, and restful
What is restful:
the corresponding Chinese is the rest type; RESTful Web service is a common rest application that adheres to restful web services, and RESTful Web services is a kind of roa (the resource-oriented Architecture) (resource-oriented architecture).
Do not repeat the reference post http://blog.csdn.net/chenxiaochan/article/details/73716617
The following diagram of the article, note
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Take a look at the red box in the picture ...
Pay attention to change
Important thing to say eight times ...
Example 1: Starting
Browser Call http://localhost:3218/api/Values/5/
Code breakpoints
The. NET core Web API is based on the request for a GET request, go to the controller to find the HttpGet identity of the +[httpget ("{ID}") in the routing template, so found the getallstudent (int id), remember, The Aciton parameter name is consistent with the routing template name [HttpGet ("{ID}")], which is the ID, if inconsistent, the parameter is not obtained.
Example 2 connecting link
Browser Call http://localhost:3218/api/Values/5/
Code breakpoints
See, is not get to ID, I never cheat
Example 3 connecting link
When all is a GET request, the template is exactly the same, I wipe, the action name is not the same, how to do?. NET core Web API how do I know which action to take?
Guess,
Browser calls
Results
Well, he did not know where to look, so the error,
Example 4, "Your example is a parameter, what about multiple parameters?" ”
Code
Browser calls
Look at the breakpoint again.
Example 5, No. RESTful style not abstract good, I need to add a custom call interface, yes, I want to go back to RPC style,
Simple, modify the routing template
Browser calls
See breakpoints
OK, so much to write, the first probe here, this is the browser address bar directly lost, so it is a GET request, post or put or delete should be a reason.
Take a look at the red box in the picture ...
A preliminary study on the blog park. NET CORE WEB API (restful style)