Giter Site home page Giter Site logo

be's Introduction

Built With

Node.js - is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside of a browser

Express.js - Lightweight web framework to bootstrap Node.js APIs

PostgreSQL - An object-relational database management system

SQLite - A lightweight software library that provides a relational database management system

Knex.js - a JavaScript query builder for relational databases including PostgreSQL, MySQL, SQLite3, and Oracle

JWT - JSON Web Token defines a compact and self-contained way to securely transmit information between parties as a JSON object

Supertest - A library made specifically for testing nodejs http servers

JEST - A JavaScript testing library

Yarn Scripts

yarn install: installs project dependencies.

yarn run server: starts the development server in watch mode on port 4000.

yarn test: runs all the test suites and displays test coverage.

Users Schema

Fields Data Type Constraints
id unsigned integer primary key, auto-increments, generated by database
first_name string required
last_name string required
email string required, unique
password string required

Posts Schema

Fields Data Type Constraints
id unsigned integer primary key, auto-increments, generated by database
title string optional
text_entry string required
created_at date (MM-DD-YYYY) generated by database
user_id unsigned integer required, foreign key, references id in users table

**_Front End: the user_id field for the posts object is for backend purposes only.

Endpoints Summary

Methods Endpoints Description
POST /api/auth/register registers a new user
POST /api/auth/login logs in a user
GET /api/users returns all users
GET /api/users/id returns a user by user id
PUT /api/users/id updates a user
DELETE api/users/id deletes a user
GET /api/journal/posts returns all journal entries/posts
GET /api/journal/users/id/posts returns a journal entry/post by user id
GET /api/journal/posts/id returns a journal entry/post by post id
GET /api/journal/users/id/search/searchtext returns a journal entry/post that matches the search query
GET /api/journal/users/id/posts/date returns a journal entry/post by user id and date
POST /api/journal/users/id/posts creates a journal entry/post
PUT /api/journal/posts/id updates a journal entry/post
DELETE /api/journal/posts/id deletes a journal entry/post

ENDPOINTS DESCRIPTION

USER ENDPOINTS

Registers a New User

POST to [https://backend-onelineaday.herokuapp.com/api/auth/register]

Takes an object:

{

"firstname": "John",

"lastname": "Doe",

"email": "[email protected]",

"password": "test"

}

Returns: an object with a welcome message, a user object, and the authorization token

{

"message": "Welcome John Doe!",

"user":

{

    "id": 8,

    "first_name": "new user",

    "last_name": "new user",

    "email": "[email protected]",

    "password": $2b$08$vkciRT2GRxdDFBgf3VLbMO7oz4loOY1uzyRBDyErulbGdr0BRuPZm"

},

"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im5ld3VzZXIxQHlhaG9vLmIsImlkIjo4LCJp0.O1rXq"

}

Login an Existing User

POST to [https://backend-onelineaday.herokuapp.com/api/auth/login]

Takes an object:

{

"email": "[email protected]",

"password": "test"

}

Returns: an object with a welcome message, a user object, and the authorization token

{

"message": "Welcome John Doe!",

"user":

{

    "id": 8,

    "first_name": "new user",

    "last_name": "new user",

    "email": "[email protected]",

    "password": $2b$08$vkciRT2GRxdDFBgf3VLbMO7oz4loOY1uzyRBDyErulbGdr0BRuPZm"

},

"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6Im5ld3VzZXIxQHlhaG9vLmIsImlkIjo4LCJp0.O1rXq"

}

GET a List of All Users

GET to [https://backend-onelineaday.herokuapp.com/api/users]

Returns: an array of user objects

{

"users": [

{

    "id": 1,

    "first_name": "john",

    "last_name": "doe",

    "email": "[email protected]",

    "password": "$2b$08$jkuT9XeczP0zxhQzSQuhsO4vlZnospu4WD0"

},

{

    "id": 2,

    "first_name": "mary",

    "last_name": "jane",

    "email": "[email protected]",

    "password": "$2b$08$jkuT9XeczP0zxhQzSQuhsO4vlZnospu4WD0"

},

{

    "id": 3,

    "first_name": "new",

    "last_name": "user",

    "email": "[email protected]",

    "password": "$2b$08$jkuT9XeczP0zxhQzSQuhsO4vlZnospu4WD0"

}    

]

}

GET a User By User Id

GET to [https://backend-onelineaday.herokuapp.com/api/users/{userid}]

*id in URL is user id

Returns: a user object

{

"id": 1,

"first_name": "john",

"last_name": "doe",

"email": "[email protected]",

"password": "$2b$08$jkuT9XeczP0zxhQzSQuhsO4vlZnospu4WD0/oykY55wFhnVJa5QCy"

}

Update an Existing User

PUT to [https://backend-onelineaday.herokuapp.com/api/users/{userid}]

*id in URL is user id

Takes an object:

{

"firstname": "John",

"lastname": "Doe",

"email": "[email protected]",

"password": "test"

}

Returns: the updated user object included hashed password

{

"id": 9,

"first_name": "John",

"last_name": "Doe",

"email": "[email protected]",

"password": "$2b$08$CT0itmYRB8SIJxIyDf.She1qGx0kgSbQRb36tSyc99zkb5A.KkyxS"

}

DELETE a User

DELETE to [https://backend-onelineaday.herokuapp.com/api/users/{userid}]

*id in URL is user id

Returns: an object with a message

{

"message": "Deleted 1 user record."

}

POSTS ENDPOINTS

GET all Posts/Journal Entries

GET to [https://backend-onelineaday.herokuapp.com/api/journal/posts]

Returns: an array of post objects

{

"posts": [

    {

    "id": 1,

    "title": "today",

    "text_entry": "lorem ipsum",

    "created_at": "10-20-2019",

    "user_id": 1

    },

    {

    "id": 2,

    "title": "tomorrow",

    "text_entry": "lorem ipsum",

    "created_at": "10-20-2019",

    "user_id": 1

    },

    {

    "id": 3,

    "title": "next week",

    "text_entry": "lorem ipsum",

    "created_at": "10-20-2019",

    "user_id": 2

    },

    {

    "id": 4,

    "title": "this week",

    "text_entry": "lorem ipsum",

    "created_at": "10-20-2019",

    "user_id": 2

    },

    {

    "id": 5,

    "title": "this month",

    "text_entry": "lorem ipsum",

    "created_at": "10-20-2019",

    "user_id": 3

    }

]

}

GET a User’s Posts by User Id

GET to [https://backend-onelineaday.herokuapp.com/api/journal/users/{userid}/posts]

*id in URL is user id

Returns: an array of post objects

[

{

"id": 1,

"title": "today",

"text_entry": "my first post",

"created_at": "10-20-2019"

},

{

"id": 2,

"title": "tomorrow",

"text_entry": "my second post",

"created_at": "10-20-2019"

}

]

GET a Post by Post Id

GET to [https://backend-onelineaday.herokuapp.com/api/journal/posts/{postid}]

*id in URL is post id

Returns: a post object

{

"id": 1,

"title": "today",

"text_entry": "my first post",

"created_at": "10-20-2019"

}

GET a Post by User Id & Search Query

GET to [https://backend-onelineaday.herokuapp.com/api/journal/users/{userid}/search/{searchtext}]

*id in URL is user id

Returns: an array of post objects

[

{

"post_id": 11,

"title": "halloween",

"text_entry": "lorem ipsum",

"created_at": "10-20-2019",

"user_id": 6

},
{

"post_id": 12,

"title": "thanksgiving",

"text_entry": "lorem ipsum",

"created_at": "10-20-2019",

"user_id": 6

}

]

GET a Post by User Id & Post Date

GET to [https://backend-onelineaday.herokuapp.com/api/journal/users/{userid}/posts/{10-21-2019}]

*id in URL is user id

*_DATE MUST BE IN THE FORMAT MM-DD-YYYY (DASHES INCLUDED)

*_PLEASE USE LEADING ZEROS FOR DAYS/MONTHS 1 – 9

Returns: an array of post objects

[

{

"post_id": 11,

"title": "halloween",

"text_entry": "lorem ipsum",

"created_at": "10-20-2019",

"user_id": 6

},

{

"post_id": 12,

"title": "thanksgiving",

"text_entry": "lorem ipsum",

"created_at": "10-20-2019",

"user_id": 6

}

]

Create a New Journal Entry/Post

POST to [https://backend-onelineaday.herokuapp.com/api/journal/users/{userid}/posts]

*id in URL is user id

Takes an object:

{

"title": "new post",

"text_entry": "lorem ipsum lorem ipsum"

}

Returns: the created post object

{

"id": 1,

"title": "new post",

"text_entry": "lorem ipsum lorem ipsum"

"created_at": "10-20-2019"

}

Update a Post

PUT to [https://backend-onelineaday.herokuapp.com/api/journal/posts/{postid}]

*id in URL is post id

Takes an object:

{

"title": "edited post",

"text_entry": "edited lorem ipsum lorem ipsum"

}

*Date/created_at is not required

Returns: the updated post object

{

"id": 1,

"title": "edited post",

"text_entry": "edited lorem ipsum lorem ipsum"

"created_at": "10-20-2019"

}

DELETE a Post

DELETE to [https://backend-onelineaday.herokuapp.com/api/journal/posts/{postid}]

*id in URL is post id

Returns: an object with a message

{

"message": "Deleted 1 journal post."

}

be's People

Contributors

tishacodes avatar

Watchers

 avatar

Forkers

roywakumelojr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.