REST APIs (concept)

Computer Science · Web development

Question 1 of 10

0

    In REST, a representation refers to:

    Stuck? Read the explanation

    Unlocks at a streak of 5 correct answers in a row.

    Print a free worksheet (PDF)

    Embed this practice on your site or class page

    Paste this HTML into your page. Students practise right there; it is free and needs no account.

    REST APIs (concept) explained

    A REST API exposes data as resources, each identified by a URL, and uses standard HTTP methods to act on them. REST is an architectural style rather than a strict protocol, so real APIs differ in the details.

    REST, short for Representational State Transfer, describes a set of constraints for web services. Clients work with resources, such as a book or a customer, by sending requests to URLs. Each request is self-contained, so the server does not need to remember earlier requests.

    Common HTTP methods map to basic operations:

    • GET reads a resource and does not change it.
    • POST creates a new resource.
    • PUT or PATCH changes an existing resource.
    • DELETE removes a resource.

    Responses carry HTTP status codes. 200 OK means success, 201 Created means a new resource was made, 204 No Content means success with no body, 404 Not Found means the URL does not refer to a resource, and 401 Unauthorized means the client has not authenticated.

    Responses usually carry data in JSON. Standard methods and codes make an API easier for other developers to learn.

    Worked example

    A bookshop API has the resource /books/42.

    1. GET /books/42 returns 200 OK with the book's data.
    2. DELETE /books/42 returns 204 No Content once the book is removed.
    3. GET /books/999 returns 404 Not Found when no book has that id.

    The status code alone tells the client the outcome of each request.

    What you will practise

    105 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.

    Example questions

    • REST APIs expose:
    • REST uses HTTP methods like:
    • GET in REST:
    • POST in REST:
    • REST responses are often:
    • HTTP status code 404 means:
    • HTTP status 201 means:
    • HTTP status code 500 indicates:

    …and 97 more.