0

I would like to design an endpoint for an api where client will only get ids in the response payload. e.g. departments/{departmentId}/users/ids, This endpoint will return userIds of all employees who belong to this deparmentId Please let me know if the above endpoint really makes sense as per the rest api standards or there should be some other way

2 Answers 2

1

Please let me know if the above endpoint really makes sense as per the rest api standards

Yup, it's perfect. "Any information that can be named can be a resource" (Fielding, 2000).

GET /departments/17/users/ids
200 OK
Content-Type: text/plain

1
2
3
4
5
...

That's fine. If you want to use some other representation (HTML, or JSON, or whatever), that's also fine.

From the perspective of a general purpose component, it's just a document. Transferring documents over a network is what HTTP is for.

Sign up to request clarification or add additional context in comments.

Comments

0

You can remove /ids suffix and use departments/{departmentId}/users and use this route for pagination. It does have sense if you are paginating users, and you expect users to be a lot, usually an API like this return the data used in a list page, so for example you could return username, email, avatar link and all the information required to the view.

There's no other solution, unless you switch to something like graphql.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.