09 Building Hateoas Clients
DodaTech
1 min read
title: Building HATEOAS Clients for Hypermedia APIs weight: 19 date: 2026-06-28 lastmod: 2026-06-28 description: Build HATEOAS clients that navigate APIs by following hypermedia links, discover available actions, and handle state transitions without hard-coded endpoint URLs. tags: [api-development, hateoas]
HATEOAS clients navigate APIs dynamically by starting at a root URL, discovering links via rel values, and following them based on semantic meaning rather than URL construction.
```python
import requests
class HATEOASClient:
def __init__(self, root_url):
self.root_url = root_url
self.current = self._get(root_url)
def _get(self, url):
response = requests.get(url)
response.raise_for_status()
return response.json()
def follow(self, rel):
"""Follow a link by its relationship name."""
links = self.current.get("_links", {})
if rel not in links:
raise KeyError(f"No link with rel '{rel}' found")
href = links[rel]["href"]
self.current = self._get(href)
return self.current
def get_available_actions(self):
"""List all available actions."""
return list(self.current.get("_links", {}).keys())
# Usage
client = HATEOASClient("https://api.example.com/api")
print(f"Available: {client.get_available_actions()}")
user = client.follow("users")
print(f"Users: {user}")
What's Next
Now learn about HATEOAS design patterns in Hypermedia APIs and HATEOAS.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro