0

I am implementing a REST end-point that converts banana to orange, but also orange to banana.

What would be the proper naming for the endpoints?

/conversions/banana/orange
/conversions/orange/banana


/conversions/banana2orange
/conversions/orange2banana


/conversions/bananatoorange
/conversions/orangetobanana

Or something else entirely?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Saita
  • 964
  • 11
  • 36

1 Answers1

1

In my opinion, REST is about resources. In this case, the resources are the bananas and the oranges. If you suppose for example that you could retrieve a banana or an orange by id, then your endpoints would be:

  1. /oranges/{id}
  2. /bananas/{id}

So i would not make a /conversions endpoint, but I would use something like this:

  1. /oranges/frombanana or /oranges/from_banana
  2. /bananas/fromorange or /bananas/from_orange

Anyway I don't really think there is a very well established naming convention, so I would not find weird any of the endpoints proposed above. Anyway, I don't find very self-explanatory the first two ones; what does /conversions/orange/banana do? Does it convert orange to banana or does it convert orange from banana? Maybe something like /conversions/banana/to/orange would be more self-explanatory.

Just for reference, here they are some APIs for cloud storage services:

  1. Dropbox APIs: https://www.dropbox.com/developers/documentation/http/documentation
  2. Box APIs: https://developer.box.com/reference

or also PayPal: https://developer.paypal.com/docs/api/balance-accounts/

kekolab
  • 801
  • 10
  • 24
  • Maybe my example was not good. I am not converting something that is a system resource. – Saita Feb 08 '18 at 18:37
  • 1
    I never mentioned a system resource. In the REST context a resource is something which can be in a certain way abstracted. Maybe here you'll fine a more complete explanation than I can ever give https://stackoverflow.com/a/10883810/1540592 – kekolab Feb 08 '18 at 20:33