nonsense
with the rise of app applications and a growing number of backend services, Microsoft will certainly provide a more convenient way to develop in this area, in addition to many excellent nodejs frameworks. This is the usual style of Microsoft, if from the development of the convenience of Microsoft is a well-deserved big brother, just fish and bear paw can not be combined, a variety of grammatical sugar to bring the development of convenience will inevitably sacrifice the performance of the program run, which is inevitable, general and efficiency is always the need for programmers to choose the topic. It's over, it's over. Today's protagonist the Web Api,web API is a technology that appears after mvc4.0, and the convenience of his creation and bringing it to me is not introduced. This article mainly talk about, I have some understanding of Web API development.
Topic one: [Frombody] Attribute modifiers
Frombody is a modifier parameter, such as: public void Post ([frombody]string name), then what is his role, in fact, his role is to query the Post request parameter is the value of name.
Note that: [Frombody] can only modify a single parameter, if it is more than one parameter, it will be encapsulated into an object for data-specific delivery, such as: public void Post ([frombody]string name,[frombody]int ID) is not a value, the ID and name are encapsulated into a Userinfo object and invoked using public void Post ([frombody]userinfo user).
Topic Two: Request Mode (Get & Post)
keyword distinction: Get requests or post requests can be distinguished by their own keywords, such as: GetUser (int id) is definitely a GET request,Getxxx (params param) format is a GET request , the same as post. Of course, there is no keyword modification method, such as: Finduser in this case, the default is the request for a POST request GET request will be reported 405 error.
Topic Three: Returning results in JSON format
This will simply set the return value of net to the JSON format, you can return Jobject or Jarray can be used Ajax to receive JSON objects. The code is as follows:
Public jobject postfinduser ([frombody]userinfo user) { new jobject (); res["name"string. Format ("{0} is a good person ~", user. Name); return Res;}
Talk about the use of Web APIs in ASP.