Skip to content

API created to replace the one currently used in my repository: PHP-CRUD.

Notifications You must be signed in to change notification settings

AugustoJDev/mongodb-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API using MongoDB for CRUD systems

API example using MongoDB with the main methods for managing users, such as: add, remove, edit...

📖 | How to use

Let's start by configuring the .env file with the credentials. Ex.:

DBNAME="augjdev"
URI="mongodb+srv://<username>:<password>@<cluester>.18kgsba.mongodb.net/?retryWrites=true&w=majority"
jwtKey="your-jwt-secret-key"

Then, download all necessaries npms to run the code. Ex.:

npm i

After the download, start the server to receive the requests. Ex.:

npm start

⚙️ | How it works

The code works mostly with the endpoint "/login". This endpoint check if the user exists in the database and return a token.

This token is used for call the others functions, like /addValues, /remValues, /editValues.

Database functions can only be called after login and with the token generated through JWT, thus preventing certain attacks.

To avoid mass spam of Requests from the same IP, I made a simple block that every 3 invalid requests, the IP is blocked until the database administrator deletes it from the list.

Example Using Postman:

Getting the Token

Getting User from DB

If you want get an especify user, add the param: [ field | value ]

🖥️ | Visit my CRUD Repo

This API was created for my CRUD, and adapted to use MongoDB instead of MySQL.

To see the version using MySQL, visit an old version of the CRUD repository, as the codes will still be functional there.

Why did I make this change? Because I'm more adapted to a non-relational database than a relational one.

About

API created to replace the one currently used in my repository: PHP-CRUD.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published