liveBook · Manning

Endpoint

As explained in Contract Testing in Action

An API endpoint is a network-accessible operation at a specified URL and method through which a client interacts with an API.

When a client requests movie data, an endpoint provides the address and operation that route the request to the appropriate server behavior. A GET request to /movies returns all movies, while /movie/:id uses a route parameter to find one movie. section 4.3.1

An API endpoint is a network-accessible operation identified by a URL and method. Its route connects a client request to application logic and determines the response, including errors such as “Movie not found.” section 4.3.1

A practical endpoint implementation separates these responsibilities:

  • Define application operations such as retrieving all movies, finding a movie by ID or name, inserting a movie, or retrieving the first movie. section 4.3.1
  • Register routes that map HTTP requests to those operations; route parameters capture values embedded in a URL. section 4.3.1
  • Start the provider service, import its data, listen on an available port, and expose the endpoint to clients. section 4.3.1

Movies API

A provider registers GET /movies to send the complete movie collection and GET /movie/:id to return the matching movie. Requesting /movie/1 returns The Shawshank Redemption; an unknown ID returns a 404 response. In contract testing, a search-suggestions endpoint can instead be exercised through a real provider while the E2E test uses a mock. section 4.3.1 section 12.4

...

const movies = new Movies();

server.get('/movies', (req, res) => {
  res.send(movies.getMovies());
});

server.get('/movie/:id', (req, res) => {
  const movie = movies.getMovieById(req.params.id);
  if (!movie) {
    res.status(404).send('Movie not found');
  } else {
    res.send(movie);
  }
});

...

Inspect the concrete Express route definitions for collection retrieval, parameterized lookup, and not-found handling. section 4.3.1

How Contract Testing in Action covers it

How deep it goes
Explains routes, parameters, responses, errors, and startup, while noting that real projects require additional error handling and unit tests.
Examples
Demonstrates movie collection and lookup routes, a 404 response, and a search-suggestions endpoint tested through Pact.
What you can do after
Build it from scratch by defining operations, registering routes, importing data, starting a server, and testing provider interactions.
How it connects
Connects HTTP methods, URL routes, route parameters, client requests, provider services, and contract testing.

Also explained in

Compare how 26 books explain endpoint →

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.