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





















