API design basics (concept)

Computer Science · Software engineering

Question 1 of 10

0

    The HTTP status code 500 indicates:

    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.

    API design basics (concept) explained

    An API, or application programming interface, is the set of requests a program offers to other programs. Good API design makes requests predictable, names things consistently and tells callers clearly when something goes wrong.

    An API defines the operations a client can perform, the inputs each one accepts and the output it returns. Callers depend on this contract, so changing it can break other programs. Designing it carefully before it is published is easier than fixing it later.

    Key design choices include:

    • Naming: use nouns for resources and keep names consistent across the API, for example users and orders rather than a mix of getUser and order_list.
    • Input validation: check inputs and reject bad ones with a clear message.
    • Pagination: return large lists in pages, with a page size and a way to request the next page.
    • Errors: return consistent error responses that say what went wrong.
    • Versioning: plan how breaking changes will be introduced, for example by publishing a new version path.

    Callers see only the API. Internal code can change freely as long as the contract stays the same.

    Worked example

    An endpoint returns 250 items, and the page size is 20 items.

    1. Number of pages: 250÷20=12.5250 \div 20 = 12.5.
    2. A partial page still needs its own request, so round up: ⌈12.5⌉=13\lceil 12.5 \rceil = 13 pages.
    3. The last page holds 250−12×20=10250 - 12 \times 20 = 10 items.

    Check: 12×20+10=25012 \times 20 + 10 = 250, so 13 requests cover every item.

    What you will practise

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

    Example questions

    • An API is:
    • Endpoints are:
    • Good APIs are:
    • API versioning:
    • Rate limiting:
    • HTTP GET is typically used to:
    • HTTP POST is typically used to:
    • A JSON object is written with:

    …and 97 more.