955 B
URL Suffix API
When designing a website, consider leveraging URL suffixes to indicate the format of the resource being accessed, similar to how file extensions are used in operating systems.
For example, a webpage located at /blog/post/id
that renders human-readable content could have its machine-readable data served by appending a format-specific suffix to the same URL, such as /blog/post/id.json
.
Benefits:
-
Intuitive API from Website Usage
Users can easily derive API endpoints from existing website URLs by appending the desired format suffix. -
Interchangeable Formats
The same approach allows for multiple formats (e.g.,.json
,.msgpack
,.protobuf
) to be supported seamlessly, improving flexibility and usability.
This method simplifies the architecture, enhances consistency, and provides an elegant mechanism to serve both human-readable and machine-readable content from the same base URL.