RESTful API design - Pepetti/PWP GitHub Wiki

Important information for Deadline 3

‼️  This chapter should be completed by Deadline 3 (see course information at Lovelace)


📑  Chapter summary In this chapter, the students must design the RESTful API.The minimum requirements are summarized in the Minimum Requirements section of the Project Work Assignment. Note that if you do not meet Minimum Requirements this section wont be evaluated.

SECTION GOALS:

  • Understand REST principles
  • Understand connectedness and/or hypermedia
  • Design a small API
  • Write API documentation

You have two options:

  1. Implement the API using a non-hypermedia format (RESTful CRUD). In this case, it is mandatory that all your resources are connected. You cannot get full points in this section if you do not design your API using an hypermedia format
  2. Using an hypermedia format. Lots of examples provided in Exercise 3. You can get full points. In this case you need to clearly include in the documentation a profile with link relations and semantic descriptors.

The recommended step-by-step process  is:

  1. Identify all the resources to be exposed by the Web API. To that end, students should make an abstraction of the concepts defined in section 1. Be aware that a one-to-one mapping between the resources and the concepts defined in section 1 is not usually the best option. Sometimes it is better to pack several concepts in the same resource.
  2. Establish the resource hierarchy and assign a URI to each resource.
  3. Establish relations and possible actions among resources. Create the state diagram of your API.
  4. Expose each one of the resources to the uniform interface.
  5. Design the resource representation using adequate format.
    1. Define the media type and its extension (if any)
    2. Define the profiles (if you are using an hypermedia format). Try to reuse existing profiles as much as possible. For instance, utilize schemas defined in schemas.org.
    3. Do not forget to include the format of the requests. If you are using hypermedia format and the media type does not define the format of the requests, they must be defined in the profile. Otherwise, the request formats must be defined in the documentation.
  • Define protocol attributes: headers, possible response codes ... must be clearly specified both for requests and responses.
  • Define the error conditions. When errors are triggered?
    • Define the format of each HTTP error response, including message body, status code and headers. 
    • It is recommended to use a hypermedia type for the response. This blog post contains some good recommendations.


  • ✔️     Chapter evaluation (max 25 points) You can get a maximum of 25 points after completing this section. More detailed evaluation is provided after each heading.

    RESTful API design

    Resources and relations


    📑  Content that must be included in the section
    1. Fill the table below with a description of the API resources
    2. Include a state diagram of your application, in which each resource is a state. Describe also the state transitions. To build this diagram you should reuse the diagram created in DL1. You can use online tools such as draw.io or lucidchart to create the diagrams. You have an example in the following image


    ✔️     Evaluation criteria(max 2.5 points) You can get a maximum of 2.5 points after completing this section.
    • Resource table with URLs and short descriptions is provided: 0.5
    • State diagram with transitions exists (see below): 0.5
    • State diagram follows relationships from DL1: 0.5
    • State diagram is correct, states make sense, transitions are clear and all possible transitions documented: 1.0

    ✏️ alt-text

    ✏️ alt-text

    Uniform interface


    📑  Content that must be included in the section Fill the following table with a description of how your resources are exposed to the uniform interface (GET, PUT/PATCH, POST and DELETE methods). You must describe the action executed in each request. For example, a GET request to the URL /messages/{message_id} "gets the body and the title of a specific message".


    ✔️     Evaluation criteria(max 1 point) You can get a maximum of 1 points after completing this section.
    • The uniform interface shows all possible requests and actions are described for each: 1.0

    ✏️ alt-text

    ✏️ Do not forget to include the sequence diagram

    API design


    📑  Content that must be included in the section

    Use any of the tools presented in Exercise 2 and 3 (e.g. Apiary) to document the API. Follow the format specified in that exercise also. You can take the Paypal REST API or TVflix service REST API (created by previous year students) as a model.

    For all resources you must cover:

    • The possible HTTP methods exposed by this resource
    • The headers in the request and responses
    • The media type utilized (in the response Content-Type header). If you are utilizing your own media-type you must describe it in the section Own media type implementation.
    • If you are using an hypermedia type you must provide the profile utilized, including.
      • Link relations. Include methods and format of the requests if they are defined in the media type. Use as much as possible IANA defined relations.
      • Semantic descriptors. If you utilize a descriptor used in some other profile (e.g. schema.org) provide the link.
      • If you are extending other profiles, do not forget to link to the extended profile.
    • The format of the HTTP response body, providing a clear example. If necessary, comment the example.
    • The format of the HTTP request body (just for PUT/POST), providing a clear example. If necessary, comment the example.
    • The error conditions, status code and format of the error response, providing a clear example.


    ✔️     Evaluation criteria(max 13.5 points) You can get a maximum of 13.5 points in this section:
    • You are using a hypermedia API: 3.0
    • Each request has the correct media type: 0.5
    • The media type is used according to its specification: 1.5
    • Link relations are described (either in the profile for hypermedia types, or in the resource documentation for the CRUD approach): 1.0
    • Attributes are clearly explained ( either in the profile - for hypermedia types - or in the resource documentation - for the CRUD approach -): 1.0
    • Examples are provided for each request: 0.5
    • Examples provided for each request do not contain errors: 0.5
    • Examples are provided for each response: 1.0
    • Examples provided for each response do not contain errors: 1.0
    • Examples includes error responses 0.25
    • Examples provided in error responses do not contain errors 0.25
    • Examples have correct headers: 0.5
    • Profiles are linked in each response (only for hypermedia APIs, CRUD implementation receive 0 points in this section): 0.5
    • Examples use correct status codes: 1.0
    • Design is coherent: 1.0

    ✏️ https://sportstrackerapi.docs.apiary.io/

    REST conformance


    📑  Content that must be included in the section Explain briefly how your API meets REST principles. Focus specially in the four principles: Addressability, Uniform interface, Connectedness, Statlessness


    ✔️     Evaluation criteria(max 8 points) You can get a maximum of 8 points in this section:
    • The justification is clear and coherent, and shows an understanding of REST principles: 2.0
    • The Api is addressable (no errors regarding addressability): 1.0
    • The Api uses correctly the uniform interface: 1.0
    • The Api does not hold state in the server: 0.5
    • The different resources of the API are connected, that is there are not isolated resources: 2.0
      • isolated resource is a resource that either is not linked to from anywhere, or doesn't contain links itself
    • Protocol semantics are clearly provided either by the response or by the profile (If you are using a CRUD API you won't get points in this section): 1.5

    ✏️

    Addressability

    Every resource containing information and data in this API is addressable. For example, user resource has information about user and user has days collection which has its own information. One individual day has collection of activities and each activity contains information and data about routines. Each resource is therefore addressable via URI.

    Uniform interface

    The API uses URI standard to identify a resource. The manipulation of these resources are also done with the help of URI identifying. For example, if user wants to READ or/and UPDATE user resource, it is possible with the URI identification of resources. The returned data is represented in JSON format. These resource responses are separate from the responses that the client gets.

    Even though this API blueprint is not precisely done with HATEOAS aspect in mind, the returned JSON document contains information about what kind of links the specific resource has to other resources. Therefore the user can see what other resources are available and how to access them.

    Statelessness

    Even though our API uses web tokens as a way to authenticate the user, the token itself is not stored in the server. Client side request contain every necessary information that the server side can understand and handle.

    Connectedness

    According to the API blueprint, every resource is connected to atleast one other resource. In other words, every resource contains at least one link to other resource.

    Resources allocation

    Task Student Estimated time
    ⚠️ **GitHub.com Fallback** ⚠️