# API design

**URL:** <https://forum.elixirforum.com/t/api-design/35314>\
**Category:** Questions\
**Tags:** api, phoenix, backend\
**Created:** [November 2, 2020, 10:39pm UTC](https://forum.elixirforum.com/t/api-design/35314 "2020-11-02T22:39:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fernando](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fernando/32/1456_2.png) [@Fernando](https://forum.elixirforum.com/u/Fernando)\
**Post date:** [November 2, 2020, 10:39pm UTC](https://forum.elixirforum.com/t/api-design/35314/1 "2020-11-02T22:39:58Z")

</div>

Hello. Im doing a API REST and i have doutb about the api design. I have 3 roles (admin, professionals, patients). They have diferents things what they can see or do, but also things that are very similar.

For example, and admin can see all the users and information and a patients only can see a list of professionals with limit information.

I think about two endpoints, with a Plug to ensure the role. :

```elixir
GET /api/patient/users, PatientController, :index

GET /api/admin/users, AdminController, :index

```

The other way i see, is one endpoint:

```elixir
GET /api/users

```

and in the controller make and if, to load the right information to the role, or make a plug to redirect to the right controller o path.

What is the proper way?

---

<div class="post-metadata">

**Author:** ![bottlenecked](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bottlenecked/32/11338_2.png) [@bottlenecked](https://forum.elixirforum.com/u/bottlenecked)\
**Post date:** [November 3, 2020, 5:19pm UTC](https://forum.elixirforum.com/t/api-design/35314/2 "2020-11-03T17:19:44Z")

</div>

Hi, if I think of this from a graphql perspective then the entity is always the same (‘user’) but then each resolver that would resolve sensitive fields would check to see if it should attempt to resolve the field based on credentials.

Assuming that the view of users a patient sees is a strict subset of what an admin can see for example, I’d go for the 2nd option with code that would perhaps look like this

```elixir
get_user(...)
|> add_extras(role) # eg role resolves to :admin
|> put_resp()

```

essentially ‘decorating’ the base object with extra detail if appropriate. Do note that this may increase sql query count however depending on how the data is fetched, so keep that in mind as well
