liveBook · Manning

HTTP response code

As explained in Contract Testing in Action

An HTTP status code is a numeric code in an HTTP response indicating the result of processing a request.

An HTTP response code is a numeric result that an API returns after processing a request. Consumers use it to distinguish successful retrieval, accepted creation, conflicts, and missing resources. section 4.3.3

Consumer contracts can make response-code expectations explicit:

  • Return 200 when fetching all movies or one movie succeeds. section 4.3.3
  • Return 201 when accepting a newly added movie. section 4.3.3
  • Return 409 when adding an existing movie, together with a suitable error message. section 4.3.3
  • Return 404 when deleting a movie that does not exist. section 4.3.3

Contracting a successful movie request

A Pact interaction can require GET /movies to respond with status 200, a JSON Content-Type header, and an array-shaped body. The consumer then executes the request against the mock provider, while provider verification checks the expectation against a local service. section 12.3

Listing 12.2 Supertest get movies
    test("/movies", async () => {
        await request(server)
            .get("/movies")
            .expect("Content-Type", /json/)     #1
            .expect(200)     #2
            .expect((res) => {
                expect(res.body).toMatchObject([])     #3
            })
    })

Inspect the original Supertest assertions to compare response-code, header, and body checks before converting them into contract elements. section 12.3

How Contract Testing in Action covers it

How deep it goes
Explains concrete response-code expectations and contract assertions, but does not detail HTTP status-code categories or protocol internals.
Examples
Uses movie retrieval, creation, duplication, deletion, Supertest assertions, and Pact interactions as concrete examples.
What it assumes
Assumes familiarity with API requests, responses, and integration tests while using movie-service scenarios to establish expectations.
What you can do after
Apply it via Pact to specify and verify API response-code expectations across consumer and provider tests.
How it connects
Connects HTTP response codes with consumer-driven contract testing, integration testing, API responses, HTTP headers, and response bodies.

Also explained in

Compare how 11 books explain HTTP response code →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Contract Testing in Action. The section links point to the parts of the book it draws on.