HTTP and REST API Course: Understand the Web and Design APIs

HTTP and REST APIs is an intermediate-level course of 6 lessons (about 3 h 50 min), with 18 exercises and 18 quiz questions. Prerequisites: Asynchronous JavaScript (Promises, fetch, APIs). Exercises run in the browser, with nothing to install.

  • Back-end
  • Intermediate
  • 6 lessons
  • 3 h 50 min
  • 18 exercises
  • Exercises run in the browser

The course in brief

This course explains how the HTTP protocol works and the best practices for designing REST APIs, on both the client and the server side. You will learn to choose methods and status codes, design URLs and pagination, validate JSON data, return standardized errors, master caching, CORS, and authentication, and then assemble a minimal API router. All the exercises run in JavaScript with the standard URL, Request, and Response objects, with no server and no network.

What you will be able to do

  • Read and build HTTP requests and responses, and handle URLs safely
  • Choose the right method and status code, and apply the rules of idempotency and retries
  • Design a consistent REST API with resources, filtering, sorting, and pagination
  • Validate JSON payloads and return errors in the Problem Details format
  • Configure caching (Cache-Control, ETag), CORS, and token- or cookie-based authentication
  • Implement and test a minimal API router without starting a server

Syllabus: 6 lessons

    • Describe the request/response exchange and the structure of an HTTP message
    • Break down a URL (scheme, host, port, path, parameters, fragment)
    • Work with URL and URLSearchParams in JavaScript

    HTTP request and responseURL structureHTTP headers

  1. 02

    Methods and Status Codes

    18 min
    • Choose the right HTTP method for the intent
    • Explain safety and idempotency and their consequences (retries, caching)
    • Choose and interpret the common status codes

    HTTP methodsSafety and idempotencyStatus codes

  2. 03

    Designing a REST API: Resources, URLs, and Pagination

    18 min
    • Model an API around resources and collections
    • Design consistent URLs and choose methods and statuses
    • Implement filtering, sorting, and pagination

    REST principlesURL designFiltering, sorting, and pagination

  3. 04

    JSON Bodies, Validation, and Error Format

    18 min
    • Send and read JSON bodies with the right headers
    • Validate a payload and respond with the right status
    • Return structured errors in the Problem Details format

    JSON bodies and Content-TypeData validationStructured errors (Problem Details)

  4. 05

    Essential Headers: Caching, CORS, and Authentication

    20 min
    • Control caching with Cache-Control, ETag, and conditional requests
    • Explain and configure CORS, including preflight requests
    • Transmit authentication with a Bearer token or a secure cookie

    HTTP cache and ETagCORSHTTP authentication

  5. 06

    Assembling a Minimal API Router

    20 min
    • Associate methods and parameterized paths with handlers
    • Automatically produce 404 and 405 with the Allow header
    • Assemble a testable CRUD mini-service with the standard Request and Response objects

    RoutingRequest → Response handlersCRUD service

Final project

A Reservation Management API, Tested Without a Server

Design and implement in JavaScript the API of a room-booking service. First write the contract (resources, URLs, methods, status codes, error format), then implement it with a (Request) => Response style router: creation, retrieval, modification, and cancellation of bookings, a filtered and paginated list, payload validation, Problem Details errors, ETag on the list of rooms, CORS headers for the front-end application, and Bearer token authentication. Everything is covered by node:assert tests that build Requests without a network.

Deliverables

  • The API contract (table of routes or OpenAPI specification) with example requests and responses
  • The code of the router, the middleware (authentication, CORS, logging), and the handlers
  • A validation module and an application/problem+json error generator
  • Pagination of the bookings list with next/previous links
  • Handling of time-slot conflicts with 409 and conditional requests with ETag/304
  • A test suite covering success, 401, 403, 404, 405, 409, 415, 422, and 304

Assessment criteria

  • Resource-oriented URLs and methods that follow their semantics
  • Exact status codes and associated headers (Location, Allow, WWW-Authenticate, ETag)
  • Strict input validation without mass assignment
  • Consistent, useful errors with no information leakage
  • Correct CORS policy and authentication
  • Complete, readable tests that run without a server

Frequently asked questions

What is the difference between HTTP and a REST API?

HTTP is the protocol that carries requests and responses on the web. REST is an architectural style that uses HTTP consistently: resources identified by URLs, manipulated with standard methods and explicit status codes.

Is this course useful for a data scientist?

Yes. Data often comes from APIs and models are often exposed through an API. Knowing how to build requests, handle pagination, authentication, and errors, and how to serve a prediction as JSON is part of the job.

Do I need to know how to program a server to take this course?

No. Knowing JavaScript and asynchronous code (promises, fetch) is enough. The exercises test the logic with the standard Request and Response objects, without installing or starting a server. The following courses in the path apply these concepts to a back-end framework.

Why do I get CORS errors in my browser console?

The browser blocks reading a response from another origin if the server does not allow it with the appropriate CORS headers. The lesson on headers explains how to configure Access-Control-Allow-Origin and preflight requests.

This course, told for your job

Say what you want to be able to do: “HTTP and REST APIs” takes its place in your path, with examples from your field. The concepts stay those of the course.

The preview is free, and you can take the courses one at a time without paying. The path only contains lessons from the catalogue.