/photoAPI

Primary LanguageJavaScript

Welcome to PhotoAPI

Project status

Badge Badge Badge Badge

Index

1. Abstract

That project aims: (I) Build a simple Application Programming Interface (API) software solution, using Express framework and JavaScript programming language, capable to get read, delete and serve photos by http requests; functioning as virtual Network Attachment Storage (II) Manipulate image files using JavaScript. (III) Use regex expressions to validate data. (IV) Implement the create, read, update and delete users data methods using mongoose and a NoSQL database (MongoDB). (V) Make explicit one option to auth users and protect some API routes.

Key-Words: Express framework; JavaScript Lang; MongoDB; HTTP verbs;

2. API Routes

Exists two main routes in this API: Users and Photos. Using differents HTTP verbs, the clients softwares can requests the creation, reading, updating and deleting data about this two entitys. That project was designed and implemented thinking about a house demands, then the code here introduced was modeled follow simple requisities.

HTTP Verb Routes Description Required Params
POST serverAddr:port/users Create a new user fullName, email and password
POST serverAddr:port/users/login Generate a Token E-mail and password
PUT serverAddr:port/users Update user data fullName, password and Token
DELETE serverAddr:port/users Delete a user Just require token
GET serverAddr:port/photos Return a list of photo paths Just require token
POST serverAddr:port/photos Update one photo and insert that path into Mongo DB A file with jpeg or png or jpg extension and Token
DELETE serverAddr:port/photos/:idPhoto Remove a photo path of MongoDB and delete one image idPhoto and Token
GET serverAddr:port/imgs/:somePath Allows visualize a image file Path

Json response examples

// Sucess in new user registration process
{
    "msg":"Welcome to Photo API"
}


// Case a unauthenticated user try execute some protected route
{
	"error":"Make login to use this functionality"
}

// Returns of login route
{
	"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJwaG90b0FQSSIsImlhdCI6MTYxODU1NjkyNCwiZXhwIjoxNjUwMDkyOTI0LCJhdWQiOiIiLCJzdWIiOiIifQ.lSM2_7fVKi7tLrBxLYGgkxuNfbuWoqUbhJPqdB0Bcs8",
	"userData": {
		"id": "679ed003z55831c0c1d01c",
		"fullName": "luiz gabriel",
		"email": "imagine a valide e-mail addr here",
		"password": "hashed password"
	}
}

// Photo path list
{
	"msg":  "See your photos",
	"index":
	[
		{
			"id":  "607938f91f93620c90a42c0e",
			"path":  "src\\imgs\\1618557177731pp.jpg",
			"idUser":  "6078fed003b39531c0c1d01c"
		},
		{
			"id":  "607938f91f93620c90a42c0e",
			"path":  "src\\imgs\\1618557177731pp.jpg",
			"idUser":  "6078fed003b39531c0c1d01c"
		}
	]
}

4. Dependencies or libraries

Bcrypt: 5.0.1 Bcrypt Docs

Del: 6.0.0 Del Docs

Express: 4.17.1 Express Docs

JsonWebToken: 8.5.1 JsonWebToken Docs

Mongoose: 5.12.2 Mongoose Docs

Morgan: 1.10.0 Morgan Docs

Multer: 1.4.2 Multer docs

5. Mongo DB

Document oriented, Mongo DB is a database that sends responds requests by JSON format. It was chosen because it has an excellent ability to handle requests easily. The used version was Mongo DB Community Server.

You can read more about Mongo or make download at link: Mongo DB Community