Prisma with REST — Authentication, and Authorization

Shweta Pawar
Aug 11, 2020 · 1 min read

In the last story, I covered how to setup Prisma. Now we will create Rest APIs using Prisma.

To use Prisma client in Nodejs, first setup Nodejs

A. Project setup

Let’s start

  1. Open server.js and create routes to API:

2. Authentication:

For authentication first, add the required dependencies to the project:

npm add lodash bcrypt jsonwebtoken

Uses:

  1. jsonwebtoken
  2. bcrypt
  3. lodash

3. In API folder create user.js file for creating RESTful API for the user register, a user login, and user delete.

2. In the API folder create file company.js and add the following code.

In the API folder, create another file employee.js and write the following code.

https://gist.github.com/ShwetaRPawar/633e5f0b581661ca04e4cd39c97e0ad3

Testing

Run the project by typing the command:

npm run start

Here, You can refer to the previous stories for testing APIs :

  1. For authentication and authorization.
  2. For testing company and employee APIs

Conclusion:

We have successfully created Restful APIs using Prisma. 👏

nonstopio

A Bespoke Engineering Studio

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store