i have a order catalogue web site and i want to create a REST API so people can create their own apps and Add an Orde开发者_如何转开发r or Update an existing order:
Lets say an order has:
- OrderId
- Product
- Quantity
- ShippingType
So i need some API to allow someone to send in a new order (orderid would be blank as that would be in the response).
- How do you deal with passing in items like Product or Shipping type. These are tables in my db and are keyed off their own specific primary key id. Should the NewOrder API ask for a string name for these fields, should it ask for the id. If it asked for the ID, that would assume they would have to call the GiveMeProductList() method upfront (which gives you the name and id of all product as a dataset).
What is the standard for dealing with this?
Martin Fowler has a good post about the steps toward the glory of REST that you might find useful to come up with REST API.
The media type that I use for sending this information to the server can handle both scenarios, Id and Code/Name. If the user enters the product code manually then I send up the code, if the user asks to pick from a list then I provide the list and send back the Id.
精彩评论