Skip to content

Workflow

Henrique Rocha edited this page Aug 25, 2021 · 1 revision

The workflow is as follow:

  1. The API starts running on PORT and begins the connection with MongoDB using MONGO_CLIENT_URL.
  2. It will accept only GET methods on the routes detailed at Endpoints.
  3. When it receives a GET request on the main route (api/v1/:user) it will do the following
    • Call the Intra API:
      1. First it will send a POST request to https://api.intra.42.fr/oauth/token to get an authorization token, using CLIENT_ID and CLIENT_SECRET.
      2. Then using the received token, it will send a GET request to https://api.intra.42.fr/v2/users/:user to get a JSON of information about the user.
    • Parse the received JSON.
    • Send the parsed JSON to the client.
    • Persist it on MongoDB Atlas.
  4. When stopped (SIGTERM), it frees everything and shuts down gracefully.

Considerations:

  • If the requested user isn’t in the database, it will be added, but if it already exits, only its informations are updated.
  • Because of the limitations of C, it can only respond one request at a time.
  • If you send invalid methods, you’ll get an 400.
  • If you send a method on a invalid URI, you’ll get an 404.
  • If you send a non-implemented method on a valid URI, you’ll get an 405.

Clone this wiki locally