Is there no one who spits out the Web Api for the ASP?

Source: Internet
Author: User

An app new project in order to fashion, with the ASP. NET Web API, perhaps I am not too familiar with, after a few days of painstaking research, the Web API really does not use, it belongs to incompatible.

Create a new API controller, probably the following method

 Public ienumerable<string> Get ();  Public string Get (int  ID);  Public void Post ([frombody]string  value);  Public void Put (int ID, [frombody]string  value);  Public void Delete (int id);

The return value of these methods obviously does not meet the requirements, for example, when the iOS or Andriod side request Delete, delete is not successful, it is not known, so must be wrapped in the return results, similar

 Public class Myresponse    {        publicintgetset;}          Public string Get Set ; }          Public Object Get Set ; }    }

Then the API controller method becomes

 Public myresponse Get ();  Public Myresponse Get (int  ID);  Public Myresponse Post ([frombody]string  value);  Public Myresponse Put (int ID, [frombody]string  value);  Public Myresponse Delete (int id);

So here's the problem------------------------------------------------

1. In public myresponse Get (int id); method, if Content-type is Application/xml, then the serialization error will be reported, there is no, not very convenient to return XML, my solution is: Remove Xmlformatter in global, the client is used application /json Request

 Public Myresponse Get (int  ID) {            var model = userrepository.find (ID);             return New Myresponse ()            {                = model            };}

If so, why not use the Jsonresult in MVC?

2. I understand the purpose of the Web API design, what semantics ah, what resources ah, but so many methods are not serious enough to use Ah, such as user, the need to register, login, change the password, modify data, verify the uniqueness of the user name, etc., a get PUT POST delete how enough, Of course I know there are other type, but those English words too jerky, tell the terminal friend this with LOCK, that with SEARCH? So finally I changed the routing, like

CONFIG. Routes.maphttproute (                "actionapi",                "api/{ Controller}/{action}/{id}",                new {id = routeparameter.optional}            );

Then hit the HttpPost httpput on the action. Wait, all this kind of, why do not use MVC,MVC in the action not the same can be called get post

3. Think this is the end, no, do the terminal colleague said, you put the method, you can not use AH. Perhaps, like Appcan this middleware, perhaps only support get,post, after I finally change httpput httppost, everything is okay

Look at the so-called Web API, is this still a Web API? In fact, with MVC in Jsonresult no different, do not know why Microsoft out of such a thing??

Is there no one who spits out the Web Api for the ASP?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.