Used to do Web projects, using MVC. Recently the company needs to go online app, ready to use WEBAPI interface, with the habit of mvc,api or there are a lot of details of the place feel very "pit" ...
The first pit, WEBAPI the default routing rules are different, by naming to match the calling method, matching only the controller and parameters, not matching the action ... I, no! How can I use this fast two-year-old MVC to be able to withstand such a heavy blow!!! Apart, clicks, routing Configuration plus action ... The mood instantly comfortable a lot, and then looked out of the window of the gray day, I clearly saw the blue sky and white clouds.
Second pit, a simple parameter of the Post method Leng Gets the value passed in. A whole morning ah, toss to toss, in the loss of the original dozens of hair and tens of thousands of scalp cells after finally found the answer: multi-parameter post submission, the interface needs to write the parameters into an object, plus [frombody], everything OK A simple parameter of the Post interface must not be made into an object, because I am a very neat of the yards, so, began and Baidu Search war .... Do not search do not know, a search startled, the original Webapi have come out for several years! Originally in the 12, the Great God Gate has been discussed in the blog Park ... 12 What am I doing, eh, think ~ only sophomore junior Ah I go, not hooking up elementary school sister is in the ... Well, in order to show that I have also worked hard for this problem, paste some other people's solutions: to build a class, parameters thrown inside, a parameter is also so dry, this is one. interface so write [Frombody] string content, it is said that jquery so write $.post ('/api/wocao ', {': ' Pit Daddy '}) is no problem, the specific God horse Android Ah iOS ah, saying that I am the bird thing, then, Take jquery and show them, "I can do jquery, you can't do it is your problem, you have to think of ways to ..."
Then say the first pit, like landlord I do this is definitely not suitable drops, Cairo said, elder brother is a moral integrity program Ape!!! Well, the route changed back, the action named according to rules, this [httpget][httppost] label all kill, we also write a RESTful standard API interface, do a regular army, do a good yard, do a good man ... However, a controller inside the two interface parameters is exactly the same swollen? The table says impossible, write write the absolute force will appear this problem, heart 100,000 grass mud horse ran over ... You know what a terrible thing it is to force a moral integrity programmer to get rid of a very beautiful parameter name, at least I've changed it with tears. All blame oneself at that time the university entrance examination fills a volunteer when believe the Deskmate Jen suggestion, but think he is now in Gansu of some deep mountain inside paved rails, my heart also balanced a bit.
All right, it's off. Other "pit", Tomorrow again to rip ...
Those "pits" encountered by novice. NET Web APIs