Skip to content

ch-ance/Node-Back-End-Starter

Repository files navigation

Node Back End Starter

The purpose of this repository is to provide a baseline starting point for a Node API with user authentication. I've found myself repeating some of these same basic steps each time I make a new API, and thought it would be helpful to have all of my best practices put into a convenient and ready to use repo.

The project is written entirely in Typescript - if you wish to use this starter kit you may elect to continue writing and compiling Typescript code, or you can simply move into the "build" folder and work directly with Javascript.


API Documentation

ENDPOINTS

Links Endpoints
POST Registration /api/auth/register
POST Login /api/auth/login
GET User by ID /api/users/id/:id
GET User by Username /api/users/username/:username

[POST] Registration

/api/auth/register

Payload: a JSON body object, containing a user object.

Required: username & password

{
  "user": 
        {
            "username": "user1",
            "password: "pass1",
            "email": "user@email.com",
            "first_name": "John",
            "last_name": "Smith"
        }
}

Returns:

{
  "id": 1,
  "username": "user1",
  "email": "user@email.com",
  "first_name": "John",
  "last_name": "Smith"
}

[POST] Login

/api/auth/login

Required: username & password

{
    "user": 
        {
            "username": "user1",
            "password": "pass1"
        }
}

Returns:

{
    "message": "Welcome user1",
    "token": a JSON web token
}

[GET] User by ID

/api/users/id/:id

Restricted endpoint, requires a valid json web token

GET https://localhost:5000/api/users/id/1

Returns:

{
    "username": "user1",
    "email": "user@email.com",
    "first_name": "John",
    "last_name": "Smith"
}

[GET] User by Username

/api/users/username/:username

Restricted endpoint, requires a valid json web token

GET https://localhost:5000/api/users/username/user1

Returns:

{
    "username": "user1",
    "email": "user@email.com",
    "first_name": "John",
    "last_name": "Smith"
}

About

A starter kit for a Node API with user registration and authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published