/REST-API-TypeScript

API REST, PRISMA, Mariadb, TypeScript

Primary LanguageTypeScript

API REST - TypeScript and Prisma

This is simple Example of an API rest build on Node.js with TypeScript.

Why TypeScript?, Take a look Link

Tecnologies and tools Used

  • Prisma- ORM for SQL and NoSQL databases
  • Prisma-Client - An auto-generated and type-safe query builder that's tailored to your data
  • Node.js - My second home
  • JWT - JSON Web Token for node.js
  • TypeScript - A strongly typed programming language that builds on JavaScript
  • Express.js - Most used JavaScript framework for backend aplications
  • morgan - A HTTP request logger middleware for Node. js
  • crypto-js - JavaScript library of crypto standards.
  • MariaDb SQL Database
  • cors - Shorthand for Cross-Origin Resource Sharing

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

PORT Server Port

DATABASE_URL DB url

SALT Secret for password encryption

JWT_SECRET JWT secret

Deployment

There are to Steps, if you want to test in a dev enviroment to the next

  npm run dev

In case you want to run on production run:

  npm run build 

and

  npm run start

"build" complies TypseScript code to JavaScript code, finally "start" runs node with JavaScript Code

API Reference

Create User

  POST /api/auth/signup
Parameter Type Description
username string Required. new username
email string Required. new user email
password string Required. new user password
firstName string Required. new user firstName
lastName string Required. new user lastName

Signed User

  POST /api/auth/signin
Parameter Type Description
email string Required. user email
password string Required. user password

Create Post

  POST /api/post/
Parameter Type Description
title string Required. post title
content string Required. post content
authorId string Required. author ID

Files

Main files

Files Description
dist Compiled JavaScript code
prisma Prisma schema and sql history
src Typescript modules
package.json Node.js configurations
tsconfig.ts Typescript configurations

SRC files

Files Description
config Load Env variables
controllers All endpoitns controllers
models moongose models , not being used, replaced for prisma
routes All endpoints routes
services All kind of services like queries, validations
app.ts Express file configuration
database.ts Moongose connections , not being used
index.ts Init app

Authors