A simple API to simulate fetching profiles, pagination and rate limiting.
The intention of this API is to be used during pair programming exercises, to simulate a real-world scenario where we need to fetch data from an external API, and we need to handle rate limiting.
- All attributes, except
idor explicitly stated, are randomly generated on every response. - Profile
2000hasattributes.properties.cat: "Felix". - Profiles with even
idhaveattributes.properties.dog. - Profiles with odd
iddo not haveattributes.properties.dog. - The API returns 403 status code if the rate limit is exceeded.
There are some defaults that can be configured, such as the rate limit and the number of returned profiles.
Configuration is in config/config.exs.
Parameters:
limit: Number of profiles to fetchcursor: Cursor to fetch the next page of profiles
/api/profiles
/api/profiles/:id
HTTP/1.1 200 OK
x-ratelimit-limit: 10
x-ratelimit-remaining: 5
x-ratelimit-reset: 12
x-request-id: F-g3q-rD1ljat0MAAAEB
{
"data": [
{
"attributes": {
"created_at": "2024-01-02T17:26:57.571406Z",
"email": "ebba1948@aufderhar.biz",
"first_name": "Nora",
"last_name": "Gerlach",
"phone_number": "+44909686055",
"properties": {
"pizza": "Extra-Large Meat Feast"
},
"updated_at": "2024-09-07T04:41:39.383496Z"
},
"id": 1,
"type": "profile"
}
],
"links": {
"next": "/api/profiles?cursor=Mg==",
"prev": null,
"self": "/api/profiles?cursor=MQ=="
}
}
To start your Phoenix server:
- Run
mix setupto install and setup dependencies - Start Phoenix endpoint with
mix phx.serveror inside IEx withiex -S mix phx.server
Now you can visit localhost:4000 from your browser.