0

Let's say I have a REST endpoint where the order of inputs for a given field is important:

POST Request: api.myrestendpoint.com/evolution-timeline/
inputs: {'this_list_should_be_ordered' : [ 'reptiles', 'birds', 'mammals'] }

I'd like suggestions on how one can specify the contract so its clear to the client that the order of inputs is important in order to get sensible results. (i.e. passing in the input as ['mammals', 'reptiles', 'birds'] wont give a sensible output).

Notes: Couple of obvious solutions are make the field name so it suggests ordering is important or having the swagger/any other documentation tool state the ordering is important...

here's obviously some validation that will go into figuring whether the ordering is important on the server side, but in interest of making the api faster, i'd like to make it obvious to the user that the ordering does not make sense/and do some lightweight validation of inputs...

  • It's going to depend on the context. If the order matters because they need to be consecutive and time-ordered, maybe use start and end or first and last parameters instead, for example. – jonrsharpe Jul 8 at 14:27
  • Is it really that the input ['mammals','reptiles','birds'] is invalid, or just that it gives a different result than ['reptiles','birds','mammals']? Would ['reptiles',' mammals'] or ['birds'] be valid inputs (obviously with different results)? – Bart van Ingen Schenau Jul 9 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.