0

I have a REST api built for creating orders. The behavior is such that the person who creates an order received an email back saying "You created an order XXX". This email is triggered all the time.

The api appears like this

http://api.mytestevnt.com/ordering/orders - POST with request body as the order entity json.

Now i want to give a feature to the api caller to indicate if the email notification is necessary or not. What's the best way to do this?

Sripaul
  • 2,227
  • 9
  • 36
  • 60

3 Answers3

1

I think it depends on whether email notification is data or metadata. If it's part of the order, then definitely add it to the request body. If it's metadata, you have two choices. If you think there will be lots of metadata, you can either edit the order to have a metadata section or you can POST the metadata separately. If there will only be a limited amount of metadata, I would suggest using a query parameter.

You should avoid using a header unless you control the entire path from the client to the server, because proxies or load balancers are allowed to strip non-standard headers.

Eric Stein
  • 13,209
  • 3
  • 37
  • 52
0

Include in the POST body a send_email=1 or send_email=0 param. You'll extract that, and see what the user wants to do.

Search "how to get POST variables in JAVA".

Accessing post variables using Java Servlets

Community
  • 1
  • 1
Tommy Crush
  • 2,790
  • 1
  • 15
  • 18
0

You can do like this:

  1. Add a new Java attribute(like boolean emailEnabled) in your Java Request Object for your REST service.

  2. Client side which invokes your REST service need to provide that parameter you added in your server side, you can set a default value for that too.

sendon1982
  • 9,982
  • 61
  • 44
  • thanks! I was thinking it would contaminate the actual Order resource which is the request body... – Sripaul Apr 01 '14 at 03:13
  • You are welcome. It does require you to add something in your request object, but it will not impact the other clients which do not include this new added attribute. – sendon1982 Apr 01 '14 at 10:41