Search code examples
apirestasp.net-web-apirestful-urlrestful-architecture

Which resource should I use to keep my API RESTFul?


I'm building an API to allow the client of the API to send notifications to remind a user to update an Order status. So far, there are two notifications:

  • when the user hasn't marked the order as received;
  • when the user hasn't marked the order as done.

I want to build this API to make it simple to extend to other notifications related to the order, but keep a simple URI for the clients of this API. How can I define my resources in order to keep my API RESTFul?

I was thinking about having one of these structures:

Option 1:

POST: /api/ordernotification/receive/{id}
POST: /api/ordernotification/complete/{id}

Option 2 (omit the status from the resource and post it instead):

POST: /api/ordernotification/?id={id}&statusID={statusID}

EDIT

Option 2.1 (keeping an articulated URI, as suggested by @Jazimov):

POST: /api/ordernotification/{statusID}/{id}. 

Which option is more appropriate? Is there any advantage that one option has over the other? Or are there any other option I haven't thought of?


Solution

  • I would go with something along these lines

    POST /api/order/1234/notifications/not-received
    POST /api/order/1234/notifications/not-completed
    

    Which can later be accessed via

    GET /api/order/1234/notifications/not-received
    GET /api/order/1234/notifications/not-completed
    

    Or

    GET /api/order/1234/notification/8899
    

    There's no real limitation on how semantically rich a URI can be, so you might as well take advantage of that and be explicit.