Skip to content

A simple ExpressJS server for learning and practicing purposes only.

Notifications You must be signed in to change notification settings

henrybastos/express-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express Server

The main goal of this project is to exercise:

  • ExpressJS' basic routing features.
  • GET and POST HTTP methods.
  • Error handling.
  • General protocols and standards.
  • Documentation and organization.

1. Features

There are 3 main features in this project:

  • Get all the users from the database
  • Get a specific user from the database
  • Add a user to the database

2. Endpoints

GET '/'

Shows the home page of the project.

GET '/users'

Returns all the users from the database in JSON. Example:

[
	{
		"name": "Henry Bastos da Silva",
		"username": "henry_bastos",
		"age": 19
	},
	{
		"name": "Jane Doe",
		"username": "janeDoe",
		"age": 38
	}
]

GET '/user/:username'

Returns a specific user from the database in JSON.

POST '/add-user'

Adds a user to the database. It requires the following structure:

{
  "name": "Name and Surname", 
  "username": "username", 
  "age": 99
}

Successfull if all the requirements are pleased.

Requirements:

  • name :
    • Not Unique: Do not need to be unique in the database.
    • Not null/undefined: It can not be null nor undefined, otherwise it will return /errors/null-or-undefined.
    • String: Required as a String.
  • username :
  • age :
    • Not Unique: Do not need to be unique in the database.
    • Not null/undefined: It can not be null nor undefined, otherwise it will return /errors/null-or-undefined.
    • Integer: Required as an Integer Number;

3. Error handling

All the errors are returned following the standards of the document RFC7807.

They can be found at /errors/error-types.html.

3.1. /errors/null-or-undefined.html

The current value is null or undefined.

Returned by:

{
  "type": "/errors/null-or-undefined.html",
  "title": "Value is Null or Undefined.",
  "status": 400,
  "detail": "Value is Null or Undefined.",
  "instance": "*"
}

3.2. /errors/user/username-taken.html

Username was already taken by another user.

Returned by

{
  "type": "/errors/user/username-taken.html",
  "title": "Username was already taken by another user.",
  "status": 400,
  "detail": "Username was already taken by another user.",
  "instance": "/add-user"
}

3.3. /errors/no-users-found.html

No users could be found.

Returned by

{
  "type": "/errors/no-users-found.html",
  "title": "No users could be found.",
  "status": 404,
  "detail": "No users could be found.",
  "instance": "/users"
}

3.4. /errors/user/user-not-found.html

User could not be found.

Returned by

{
  "type": "/errors/user/user-not-found.html",
  "title": "User could not be found.",
  "status": 404,
  "detail": "User could not be found.",
  "instance": "/users/:username"
}

About

A simple ExpressJS server for learning and practicing purposes only.

Resources

Stars

Watchers

Forks