{"id":17651813,"url":"https://github.com/diegovictor/devradar-api","last_synced_at":"2026-04-05T22:34:59.707Z","repository":{"id":98963935,"uuid":"329749653","full_name":"DiegoVictor/devradar-api","owner":"DiegoVictor","description":"Project developed during the OmniStack Week 10.0","archived":false,"fork":false,"pushed_at":"2025-01-22T12:24:51.000Z","size":919,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-05T08:42:42.602Z","etag":null,"topics":["api","coverage-report","databases","devradar","docker","javascript","js","mongodb","node","nodejs","omnistack","redis","rocketseat"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DiegoVictor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-14T22:28:40.000Z","updated_at":"2025-01-22T12:24:54.000Z","dependencies_parsed_at":"2024-01-09T14:07:05.694Z","dependency_job_id":"0f054fc5-ee69-4bc8-aacf-6f782985fca6","html_url":"https://github.com/DiegoVictor/devradar-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdevradar-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdevradar-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdevradar-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DiegoVictor%2Fdevradar-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DiegoVictor","download_url":"https://codeload.github.com/DiegoVictor/devradar-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246296583,"owners_count":20754632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","coverage-report","databases","devradar","docker","javascript","js","mongodb","node","nodejs","omnistack","redis","rocketseat"],"created_at":"2024-10-23T11:43:47.452Z","updated_at":"2026-04-05T22:34:59.684Z","avatar_url":"https://github.com/DiegoVictor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [API] DevRadar\n[![CircleCI](https://img.shields.io/circleci/build/github/DiegoVictor/devradar-api?style=flat-square\u0026logo=circleci)](https://app.circleci.com/pipelines/github/DiegoVictor/devradar-api)\n[![mongodb](https://img.shields.io/badge/mongodb-7.0.0-13aa52?style=flat-square\u0026logo=mongodb\u0026logoColor=white)](https://mongodb.com/)\n[![nodemon](https://img.shields.io/badge/nodemon-3.1.11-76d04b?style=flat-square\u0026logo=nodemon)](https://nodemon.io/)\n[![eslint](https://img.shields.io/badge/eslint-9.39.2-4b32c3?style=flat-square\u0026logo=eslint)](https://eslint.org/)\n[![jest](https://img.shields.io/badge/jest-30.2.0-brightgreen?style=flat-square\u0026logo=jest)](https://jestjs.io/)\n[![coverage](https://img.shields.io/codecov/c/gh/DiegoVictor/devradar-api?logo=codecov\u0026style=flat-square)](https://codecov.io/gh/DiegoVictor/devradar-api)\n[![MIT License](https://img.shields.io/badge/license-MIT-green?style=flat-square)](https://raw.githubusercontent.com/DiegoVictor/devradar-api/main/LICENSE)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\u003cbr\u003e\n[![Run in Insomnia}](https://insomnia.rest/images/run.svg)](https://insomnia.rest/run/?label=DevRadar\u0026uri=https%3A%2F%2Fraw.githubusercontent.com%2FDiegoVictor%2Fdevradar-api%2Fmain%2FInsomnia_2024-12-01.json)\n\nResponsible for provide data to the [`web`](https://github.com/DiegoVictor/devradar-web) and [`mobile`](https://github.com/DiegoVictor/devradar-app) front-ends. Permit developers to register yourself using GitHub and to find another developers. The app has pagination, pagination's link header (to previous, next, first and last page), friendly errors, use JWT to logins, validation, also a simple versioning was made.\n\n## Table of Contents\n* [Installing](#installing)\n  * [Configuring](#configuring)\n    * [.env](#env)\n    * [MongoDB](#mongodb)\n    * [GitHub OAuth App](#github-oauth-app)\n* [Usage](#usage)\n  * [Error Handling](#error-handling)\n    * [Errors Reference](#errors-reference)\n  * [Pagination](#pagination)\n    * [Link Header](#link-header)\n    * [X-Total-Count](#x-total-count)\n  * [Bearer Token](#bearer-token)\n  * [Versioning](#versioning)\n  * [Routes](#routes)\n    * [Requests](#requests)\n* [Running the tests](#running-the-tests)\n  * [Coverage report](#coverage-report)\n\n# Installing\nEasy peasy lemon squeezy:\n```\n$ yarn\n```\nOr:\n```\n$ npm install\n```\n\u003e Was installed and configured the [`eslint`](https://eslint.org/) and [`prettier`](https://prettier.io/) to keep the code clean and patterned.\n\n## Configuring\nThe application uses just one database: [MongoDB](https://www.mongodb.com).  For the fastest setup is recommended to use [docker-compose](https://docs.docker.com/compose/), you just need to up all services:\n```\n$ docker-compose up -d\n```\n\n### .env\nIn this file you may configure your MongoDB database connection, JWT settings, the environment, app's port, url to documentation (this will be returned with error responses, see [error section](#error-handling)) and GitHub's OAuth App keys. Rename the `.env.example` in the root directory to `.env` then just update with your settings.\n\n|key|description|default\n|---|---|---\n|APP_PORT|Port number where the app will run.|`3333`\n|NODE_ENV|App environment.|`development`\n|JWT_SECRET|An alphanumeric random string. Used to create signed tokens.| -\n|JWT_EXPIRATION_TIME|How long time will be the token valid. See [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken#usage) repo for more information.|`7d`\n|MONGO_URL|MongoDB's server url.|`mongodb://mongo:27017/devradar`\n|GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET|GitHub's OAuth App credentials. See [GitHub OAuth App](#github-oauth-app) for more information.| -\n|DOCS_URL|An url to docs where users can find more information about the app's internal code errors.|`https://github.com/DiegoVictor/devradar-api#errors-reference`\n\n### MongoDB\nStore all application data. 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:\n```\n$ docker run --name devradar-mongo -d -p 27017:27017 mongo\n```\n\n### Github OAuth App\nFirst you need to create a [GitHub OAuth App](https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app), just remember to configure the field `Authorization callback URL` with the project's [`web`](https://github.com/DiegoVictor/devradar-web) version home page url.\n\n![GitHub OAuth App](https://raw.githubusercontent.com/DiegoVictor/devradar-api/main/screenshots/github_oauth_app.png)\n\n\u003e If you are running the application local I recommend you to use [ngrok](https://ngrok.com) to export a url to access the application. (e.g. `https://25752eff.ngrok.io`)\n\n# Usage\nTo start up the app run:\n```\n$ yarn start\n```\nOr:\n```\n$ npm run start\n```\n\n## Error Handling\nInstead of only throw a simple message and HTTP Status Code this API return friendly errors:\n```json\n{\n  \"statusCode\": 400,\n  \"error\": \"Bad Request\",\n  \"message\": \"You are already registered\",\n  \"code\": 140,\n  \"docs\": \"https://github.com/DiegoVictor/devradar-api#errors-reference\"\n}\n```\n\u003e Errors are implemented with [@hapi/boom](https://github.com/hapijs/boom).\n\u003e As you can see a url to errors docs are returned too. To configure this url update the `DOCS_URL` key from `.env` file.\n\u003e In the next sub section ([Errors Reference](#errors-reference)) you can see the errors `code` description.\n\n### Errors Reference\n|code|message|description\n|---|---|---\n|140|You are already registered|The GitHub's user is already registered.\n|144|Developer does not exists|The `id` sent not references an existing developer in the database.\n|531|An error ocurred while trying to exchange a GitHub's access token|An error occurred during the request to get the user's access token on GitHub API, look the `details` key for more information.\n|532|An error ocurred while trying to retrieve the user from GitHub|The request to get GitHub user's data from GitHub API throw an error. Look the `details` key for more information.\n|240|Missing authorization token|The Bearer Token was not sent.\n|241|Token expired or invalid|The Bearer Token provided is invalid or expired.\n\n## Pagination\nAll the routes with pagination returns 10 records per page, to navigate to other pages just send the `page` query parameter with the number of the page.\n\n* To get the third page of incidents:\n```\nGET http://localhost:3333/v1/developers?page=3\n```\n\n### Link Header\nAlso in the headers of every route with pagination the `Link` header is returned with links to `first`, `last`, `next` and `prev` (previous) page.\n```\n\u003chttp://localhost:3333/v1/developers?page=7\u003e; rel=\"last\",\n\u003chttp://localhost:3333/v1/developers?page=4\u003e; rel=\"next\",\n\u003chttp://localhost:3333/v1/developers?page=1\u003e; rel=\"first\",\n\u003chttp://localhost:3333/v1/developers?page=2\u003e; rel=\"prev\"\n```\n\u003e See more about this header in this MDN doc: [Link - HTTP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link).\n\n### X-Total-Count\nAnother header returned in routes with pagination, this bring the total records amount.\n\n## Bearer Token\nA few routes expect a Bearer Token in an `Authorization` header.\n\u003e You can see these routes in the [routes](#routes) section.\n```\nDELETE http://localhost:3333/v1/developers Authorization: Bearer \u003ctoken\u003e\n```\n\u003e To achieve this token you just need authenticate through the `/sessions` route and it will return the `token` key with a valid Bearer Token.\n\n## Versioning\nA simple versioning was made. Just remember to set after the `host` the `/v1/` string to your requests.\n```\nGET http://localhost:3333/v1/developers\n```\n\n## Routes\n|route|HTTP Method|pagination|params|description|auth method\n|:---|:---:|:---:|:---:|:---|:---:\n|`/sessions`|POST|:x:|Body with user's `code`.|Authenticates developer, return a Bearer Token and developer's information.|:x:\n|`/search`|GET|:x:|`techs`, `latitude` and `longitude` query parameters.|Search nearest developers with the same techs.|:x:\n|`/developers`|GET|:heavy_check_mark:|`page` query parameter.|List developers.|:x:\n|`/developers/:id`|GET|:x:|`:id` of the developer.|Return one developer.|:x:\n|`/developers`|POST|:x:|Body with developer's `techs`, `latitude`, `longitude` and `code`.|Create new developers.|:x:\n|`/developers`|PUT|:x:|Body with developer's `name`, `bio`, `avatar_url`, `techs`, `latitude` and `longitude`.|Update one developer.|Bearer\n|`/developers`|DELETE|:x:| - |Remove one developer.|Bearer\n\n\u003e Routes with `Bearer` as auth method expect an `Authorization` header. See [Bearer Token](#bearer-token) section for more information. After users approve your [OAuth App](#github-oauth-app) on GitHub, it will redirect to the `Authorization callback URL` with a parameter `code` that should be sent in some routes, that you can see above.\n\n### Requests\n* `POST /sessions`\n\nRequest body:\n```json\n{\n  \"code\": \"32g2a27129w2qc23pch3\"\n}\n```\n\n* `POST /developers`\n\nRequest body:\n```json\n{\n  \"code\": \"6qca5876158fqq1ccat9\",\n  \"techs\": \"Node.js, ReactJS, React Native\",\n  \"latitude\": 52.1199,\n  \"longitude\": 159.0477\n}\n```\n\n* `PUT /developers`\n\nRequest body:\n```json\n{\n  \"techs\": \"Node.js, ReactJS\",\n  \"name\": \"John Doe\",\n  \"avatar_url\": \"https://avatars2.githubusercontent.com/u/15165349?s=460\",\n  \"bio\": \"Let's go!\",\n  \"latitude\": -73.0510,\n  \"longitude\": -64.7188\n}\n```\n\n# Running the tests\n[Jest](https://jestjs.io) was the choice to test the app, to run:\n```\n$ yarn test\n```\nOr:\n```\n$ npm run test\n```\n\n## Coverage report\nYou can see the coverage report inside `tests/coverage`. They are automatically created after the tests run.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fdevradar-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegovictor%2Fdevradar-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegovictor%2Fdevradar-api/lists"}