To use 42 API you need create an "Application" in your profile and generate an Bearer Token with Client ID and Cliet Secret provided to be able to make requests. So far so good, right? But Bearer Token provided just is valid for the first 7200 seconds (i.e 2 hours) and you only can perfom 1200 requests per hour. So you don't want to handle with this issues.
This project comes to solve this problem. Facilitate the use of the 42 API by managing tokens, bypassing the limit of requests by spreading through various applications and not letting other applications worry about what is not their responsibility.
You can deploy this project yourself with this guide.
Currently the project is deployed on Heroku. First, to access some endpoint, you need contact personally someone on the project team and ask for a Authorization
code.
Now you can perform a test request:
curl --request GET \
--url https://iniciativa-open-source.herokuapp.com/42/users/csouza-f \
--header 'Authorization: your_authorization'
That's it! This way you will get all information about user csouza-f
.
The idea behind this is you pass any endpoint available by 42 after https://iniciativa-open-source.herokuapp.com/42
. It's important to note that this endpoint make all requests already with /v2
. For example, this https://iniciativa-open-source.herokuapp.com/42/users/csouza-f
basically is https://api.intra.42.fr/v2/users/csouza-f
.
Here you can check all endpoints available.
The amount of pages available for a endpoint is displayed on response headers. For example, /apps
endpoint:
curl --request GET \
--url https://iniciativa-open-source.herokuapp.com/42/apps \
--header 'authorization: your_authorization'
When a request is performed, you can check out the response headers
As you can see the marked headers are the last, next and current page. So, you can paginated a endpoint using query string page={page}
this way.
Maybe you want more data per request, so you can use page[size]=100
, which is the maximum allowed from 42's API, default is 30. You can check out more on 42 API Docs:
curl --request GET \
--url https://iniciativa-open-source.herokuapp.com/42/apps?page[size]=100 \
--header 'authorization: your_authorization'
As more objects per request, pages on response headers decrease:
Or you can get all pages at once with special query string page=all
. This is in alpha and just available for /apps endpoint.
curl --request GET \
--url https://iniciativa-open-source.herokuapp.com/42/apps?page=all \
--header 'authorization: your_authorization'
How this return all pages already, no one page header is set, but you will get all pages from /apps
endpoint at once!
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.