I am working on a message request which will have complete request details used to create a record in destination.
This integration create 3 different type of records (Order, shipment, invoice) at different times i.e. it will not always possible to create all at once, so I need to let the system know to create only certain requests.
My questions, what would be the best to way to add this information in request?
Does it need to be in body of the request?
{ "OrderNumber": "1234", "operation": [ "orderentry", "shipment", "invoice" ] }
Does it need to be in path?
/Order/create?operation=orderentry
Does it need to be in seperate object? say
{ "operation": [ "orderentry", "shipment", "invoice" ], "request": { "OrderNumber": "1234", } }
If you just want to use HTTP as a transport mechanism, then everything goes. If, on the other hand, you want to develop a truly RESTful API, you should learn about REST. As a start, consider the Richardson maturity model. I don't consider an API RESTful unless it's a level 3 API, but even at level 1, you should model the API as a set of resources.
Each resource should be identified by a unique URL, so that already rules out two of the three options in the OP.
The resources should be identified by their URL, but not as suggested. At level 2, actions are indicated by HTTP verbs (
GET
,POST
,DELETE
, etc.). Thus, to support creation of an order, I'd envision an HTTP request like this:A successful request should result in a response in the 200 range (
200 OK
,201 Created
, etc.).If instead you want to create a shipment resource, you could
POST
to ashipments
collection resource:Resources like
orders
andshipments
are typically called collection resources because they represent collections of other resources. They typically support only thePOST
andGET
verbs, whereGET
would enumerate all the resources in the collection.Each
POST
against a collection resource typically results in the creation of a 'sub resource' with its own address. For example, when you create an order, the created address might be/orders/1234
. Such a resource would typically supportGET
,DELETE
, and maybePUT
, but notPOST
.I highly recommend Allamaraju Subrahmanyam's book RESTful Web Services Cookbook for anyone wanting to get into REST API design. It's easy to read and full of practical solutions.