0

I have a resource Customer:

{
"active": true,
"addresses": [...],
"company_name": "My Products",
"customer_account": "MMM474",
"customer_id": 6163,
"emails": [...],
"phones": [...],
"website": "" }

and a related resource Address.

Which url for accessing Address is more RESTful:

http://domain.tlc/api/v1/customeraddresses/[id]/

or

http://domain.tlc/api/v1/customers/[id]/addresses/

([id] is an ID of particular customer, customer_id.)

moonwave99
  • 21,957
  • 3
  • 43
  • 64
Elvin R.
  • 852
  • 1
  • 10
  • 20

4 Answers4

3

definitively option 2. It will allow you to extend the API further and keep it coincide:

http://domain.tlc/api/v1/customers/[id]/contacts/

MeTitus
  • 3,390
  • 2
  • 25
  • 49
0

For accessing the Addresses of a particular Customer I'd go with option 2.

jcm
  • 1,781
  • 1
  • 15
  • 27
0

If [id] in both cases is the ID of a particular customer, and both URLs return a list of addresses for that customer, I'd say go with option #2.

  • http://domain.tlc/api/v1/customeraddresses/[id]/ looks like a specific customeraddress resource
  • http://domain.tlc/api/v1/customers/[id]/addresses/ looks like a list of all addresses for a specific customer.

That said, they are both equally "RESTful" as they both identify a resource.

Jakob S
  • 19,575
  • 3
  • 40
  • 38
0

You can think of an URL as a partition of space into sub-spaces. Say, you have "Customers" as your root space and underneath, it contains customers which is identified with [id]. Then, under each customer=[id], there are "Addresses".

So, it will lead it to your second option:

http://domain.tlc/api/v1/customers/[id]/addresses/
Ming Chan
  • 1,938
  • 11
  • 21