In REST APIs, we often need to get a single resource. In this article, we explore how to structure those GET requests properly.
π§ββοΈ Get a Single Account by ID
To get one specific account, use:
/accounts/{id}
Example:
/accounts/adoe
This will return the account with ID adoe
.
You can apply the same idea to other resources, like:
/applications/872233
π§ Get Resource(s) by Field Value
Sometimes you want to retrieve a resource or a small list of resources based on a specific field, like email or region. Instead of creating multiple endpoints, use query parameters.
β Good Practice: use query parameters
/accounts?email=adoe@company.com
This means: Get all accounts where email equals adoe@company.com
Another example:
/accounts?region=EMEA&role=admin
This means: Get accounts in EMEA region with admin role
You can combine multiple query parameters β the order doesnβt matter.
β Bad Practice: encoding fields in the path
Avoid things like:
/accounts/email/adoe@company.com
or
/accounts/region/EMEA
It breaks RESTful conventions and is harder to maintain.
β οΈ Special Characters in IDs
Sometimes IDs or field values contain characters like @
, /
, or &
. Always URL-encode these to prevent errors. For example:
/accounts?email=adoe%40company.com
β Summary
To get a single resource or filter resources by field:
- Use
/resource/{id}
to fetch by unique ID - Use
/resource?field=value
for flexible searches - Never include filter values in the URL path
- Always encode special characters properly
- Stick to
GET
for safe, idempotent fetch operations
π Enjoying the article?
I'm building IntegrationTrails.io β a platform where you can go beyond reading and truly boost your skills through hands-on learning.
Whether you're a developer, architect, or integration enthusiast, you'll find practical guides, projects, and step-by-step experiences designed to deepen your expertise.