liveBook · Manning

Contract

As explained in React in Depth

An API is a defined interface through which software applications exchange requests and responses with another application or service.

An API is the agreed interface and data format through which an application exchanges requests and responses with a server. Remote reads and writes depend on server responses, unlike access to locally stored data. section 9.2.2 section 9.2.2

A RESTful CRUD API organizes requests around resources:

  • Treat requests as stateless and resource-centric. section 9.2.2
  • Support resource operations such as create, read, update, and delete where they make sense. section 9.2.2
  • For example, a goal-tracking service can expose session, user, and things endpoints. section 9.2.2

Coordinate geocoding

A client sends latitude and longitude to an API route. The route looks up a city and country through a third-party service, then returns a path and location data—or a 404 when no match is found. Next.js and Remix implement this route differently. section 11.3.4

Figure 9.4 When we store data locally, we can dip into the local data when we want to display it, but when we store the data remotely, we have to wait for the server to respond before we can display anything. This process has to occur every time we read or write data. Note also that every time we move from local to remote data, we have to agree on the format between the two parts of the applications; this format agreement is known as the API.
figure

Compare local data access with remote requests and see why both sides must agree on a data format. section 9.2.2

How React in Depth covers it

How deep it goes
Defines REST and CRUD, then implements geocoding routes; leaves broader API design beyond scope.
Examples
Uses goal-tracker session, user, and things endpoints plus coordinate-to-city geocoding in Next.js and Remix.
What you can do after
Build it from scratch by implementing geocoding routes that read coordinates, call a service, and return JSON or a 404.
How it connects
Connects REST, CRUD, HTTP requests and responses, remote data, and geocoding.

Also explained in

Compare how 44 books explain contract →

Related concepts

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