liveBook · Manning

REST

As explained in Go by Example

REST is an architectural approach for designing networked resources and interactions through uniform operations, commonly over HTTP.

REST is an API design approach for communication over HTTP, using uniform operations such as GET and POST. A practical service separates HTTP handlers from core business logic: handlers translate requests into service calls and return results to clients. section 8.0 section 8.1

A link-shortening REST service illustrates the structure:

  • The link package owns Link data and the Shortener service for shortening URLs and resolving keys. section 8.1
  • The link/rest package exposes HTTP handlers: Shorten accepts a link and returns a key, while Resolve uses a key to redirect to the original URL. section 8.1
  • The service begins with in-memory storage, then supports testing through Go's http and httptest packages. section 8.0 section 8.1

Shorten and resolve a link

A client sends a POST request containing a long URL and receives a short key. It then sends a GET request containing that key and receives a redirect to the original URL. section 8.1

$ curl link/shorten -d'url=https://x.com/inancgumus' #1
OQzXIiL4  #2

Shows a POST request that shortens a URL and returns a generated key. section 8.1

$ curl link/r/OQzXIiL4  #1
Location: https://x.com/inancgumus

Shows a GET request that resolves a key by redirecting to the original URL. section 8.1

How Go by Example covers it

How deep it goes
Explains REST through HTTP methods, handler boundaries, service calls, and API tests.
Examples
Uses a link-shortening API with POST-based shortening and GET-based resolution redirects.
What you can do after
Build it from scratch and test it with Go's standard-library http and httptest packages.
How it connects
Connects REST to HTTP, API design, HTTP handlers, package organization, service logic, and in-memory persistence.

Also explained in

Compare how 22 books explain REST →

Related concepts

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