Responsible for provide data to the web
and mobile
front-ends. Allows users to register yourself, see other registered users, like or dislake them and see past matches. The app has friendly errors, use JWT to logins, validation, also a simple versioning was made.
Easy peasy lemon squeezy:
$ yarn
Or:
$ npm install
Was installed and configured the
eslint
andprettier
to keep the code clean and patterned.
The application uses two databases: MongoDB and Redis. For the fastest setup is recommended to use docker-compose, you just need to up all services:
$ docker-compose up -d
Responsible to store data utilized by the websocket to alert users when a match occurs. If for any reason you would like to create a Redis container instead of use docker-compose
, you can do it by running the following command:
$ docker run --name tindev-redis -d -p 6379:6379 redis:alpine
Store all data utilized by the application. If for any reason you would like to create a MongoDB container instead of use docker-compose
, you can do it by running the following command:
$ docker run --name tindev-mongo -d -p 27017:27017 mongo
In this file you may configure your Redis database connection, JWT settings, the environment, app's port and a url to documentation (this will be returned with error responses, see error section). Rename the .env.example
in the root directory to .env
then just update with your settings.
key | description | default |
---|---|---|
APP_PORT | Port number where the app will run. | 3333 |
JWT_SECRET | A alphanumeric random string. Used to create signed tokens. | - |
JWT_EXPIRATION_TIME | How long time will be the token valid. See jsonwebtoken repo for more information. | 7d |
MONGO_URL | MongoDB connection url. | mongodb://mongo:27017/tindev |
REDIS_HOST | Redis host. | redis |
REDIS_PORT | Redis port. | 6379 |
DOCS_URL | An url to docs where users can find more information about the app's internal code errors. | https://github.com/DiegoVictor/tindev-api#errors-reference |
To start up the app run:
$ yarn dev:server
Or:
npm run dev:server
Instead of only throw a simple message and HTTP Status Code this API return friendly errors:
{
"statusCode": 400,
"error": "Bad Request",
"message": "Developer not exists",
"code": 240,
"docs": "https://github.com/DiegoVictor/tindev-api#errors-reference"
}
Errors are implemented with @hapi/boom. As you can see a url to error docs are returned too. To configure this url update the
DOCS_URL
key from.env
file. In the next sub section (Errors Reference) you can see the errorscode
description.
code | message | description |
---|---|---|
141 | Token not provided | The JWT token was not sent. |
142 | Token invalid | The JWT token provided is invalid or expired. |
240 | Developer not exists | The id sent does not references an existing developer in the database. |
A header returned in routes of listing, this bring the total records amount.
A few routes expect a Bearer Token in an Authorization
header.
You can see these routes in the routes section.
GET http://localhost:3333/v1/developers Authorization: Bearer <token>
To achieve this token you just need authenticate through the
/developers
route and it will return thetoken
key with a valid Bearer Token.
A simple versioning was made. Just remember to set after the host
the /v1/
string to your requests.
GET http://localhost:3333/v1/developers
route | HTTP Method | params | description | auth method |
---|---|---|---|---|
/developers |
POST | Body with Github username . |
Authenticates users, return a Bearer Token and user's data. | ❌ |
/developers |
GET | - | List developers not liked or disliked yet. | Bearer |
/developers/:id |
GET | id of the developer. |
Return one developer. | Bearer |
/developers/:liked_user_id/like |
POST | liked_user_id of the developer to like. |
Like a developer. | Bearer |
/developers/:disliked_user_id/like |
POST | disliked_user_id of the developer to dislike. |
Dislike a developer. | Bearer |
/matches |
GET | - | List developers you liked in the past. | Bearer |
Routes with
Bearer
as auth method expect anAuthorization
header. See Bearer Token section for more information.
POST /developers
Request body:
{
"username": "diegovictor"
}
Jest was the choice to test the app, to run:
$ yarn test
Or:
$ npm run test
You can see the coverage report inside tests/coverage
. They are automatically created after the tests run.