A RESTful API that serves my Journal Admin and Journal frontend applications. It allows to create a user for the database to safely interact with the admin app via JWT tokens. And utilizes a RESTful architecture to perform CRUD operations for the journals.
- Written in a NodeJS Framework: Express
- Uses a RESTful architecture
- Utilizes MongoDB for database needs
- Leverages JSON Web Tokens and Passport.js for authentication
- Hosted on Cyclic
- Clone the repository:
git clone [email protected]:01zulfi/journal-api.git
- Install dependencies:
npm install
- Spin up a database on MongoDB
- Add a
.env
file with the following:
MONGODB_URL="your mongodb connection url here"
SECRET="any random long string here"
- Create a user (don't include spaces in username and password):
node create-user.js <username_here> <password_here>
- Start the server:
npm run serverstart
- Accepts POST HTTP request
- Requires a
username
andpassword
in request body (req.body
) - Sends a jwt token (accessible with
token
property). The token should be saved client side (localStorage), since they are required to access the protected routes
- A GET HTTP request sends back the list of published journals (accessible with
journals
property)
- A GET HTTP request sends back a journal (
journal
) with the correspondingurlName
property
Note: All requests to the following routes must be accompanied with a Authorization Header set to "bearer ${jwt_token_here}"
- A GET HTTP request sends back the list of all journals (
journals
) in the database - A POST HTTP request saves journal in the database. Requires following properties in the request body:
title
,urlName
,content
.publish
is an optional property. Afterwards, the newjournal
is sent back
- A PUT HTTP request updates a journal with the corresponding
_id
property. Works similarly to the POST/journal
- A DELETE HTTP request deletes a journal with the corresponding
_id
property