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










