Postman collection version: https://documenter.getpostman.com/view/10409540/TzXzEHV6
This API is a simplified version of news provider API.
Challenge goal: The purpose of this challenge is to give my overall understanding of a backend application. Some of the concepts applied are:
- REST architecture;
- Authentication and permissions;
- Data modeling and migrations;
- SQL database;
- Query optimization;
- Serialization;
- Production builds.
-
Use seeders to insert at least an admin user or a command to insert a super-user, instead of using "isAdmin" as a flag.
-
Validate field types at database, returning 400 exception instead of 500;
-
Validate field types at signup endpoint;
-
Add tests;
-
Remove bodyparser (deprecated) and add “express.json” with “express.urlencoded”;
-
Return user object on signup;
-
Return user object without password but with jwt token on login;
-
Add custom validator para accept only URL type on picture field;
-
Add payload for (/api/articles?category=:slug);
-
Add payload for (/api/articles/:id);
- You'll need Node.JS 12 and PostgreSQL 10
- Install dependences with
npm install - Set environment variables creating a copy of
.env.examplein.env - Run
docker-compose upto start PostgreSQL DB - Run
npm run migration:runto execute last version migration on database - Run project with
npm run dev
- Run
npm run buildto create production build - Run
npm run prodto run production build
Final accomplishment: By the end of this challenge you’ll have a production ready API.
- Clear instructions on how to run the application in development mode [X] verified
- Clear instructions on how to create production builds [X] verified
- A good API documentation or collection [X] verified
- Models created using Objection.js [X]
- Login API:
/api/login[X] verified - Sign-up API:
/api/sign-up[X] verified - Administrator restricted APIs: [X] verified
- CRUD
/api/admin/authors[X] - CRUD
/api/admin/articles[X]
- CRUD
- List article endpoint
/api/articles?category=:slugwith the following response: [X] [kind of]
[
{
"author": {
"name": "Author Name",
"picture": "https://picture.url"
},
"category": "Category",
"title": "Article title",
"summary": "This is a summary of the article"
},
...
]-
Article detail endpoint
/api/articles/:idwith different responses for anonymous and logged users:[X] [kind of]Anonymous
{ "author": { "name": "Author Name", "picture": "https://picture.url" }, "category": "Category", "title": "Article title", "summary": "This is a summary of the article", "firstParagraph": "<p>This is the first paragraph of this article</p>" }Logged user
{ "author": { "name": "Author Name", "picture": "https://picture.url" }, "category": "Category", "title": "Article title", "summary": "This is a summary of the article", "firstParagraph": "<p>This is the first paragraph of this article</p>", "body": "<div><p>Second paragraph</p><p>Third paragraph</p></div>" }