prisma orm_具有REST的Prisma-身份验证和授权

prisma orm

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

在上一个故事中,我介绍了如何设置Prisma 。 现在,我们将使用Prisma创建Rest API。

要在Node.js中使用Prisma客户端,请先设置Node.js (To use Prisma client in Nodejs, first setup Nodejs)

A. Project setup         * npm init -y         * npm i body-parser express — save         * npm i webpack webpack-cli — save-dev

开始吧 (Let’s start)

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

    打开server.js并创建到API的路由:

2. Authentication:

2.身份验证:

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

首先进行身份验证,将所需的依赖项添加到项目中:

npm add lodash bcrypt jsonwebtoken

npm添加lodash bcrypt jsonwebtoken

用途: (Uses:)

  1. jsonwebtoken

    jsonwebtoken

  2. bcrypt

    加密

  3. lodash

    Lodash

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

3.在API文件夹中,创建user.js文件,用于为用户注册,用户登录名和用户删除创建RESTful API。

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

2.在API文件夹中,创建文件company.js并添加以下代码。

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

在API文件夹中,创建另一个文件employee.js并编写以下代码。

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

Testing

Ťesting

Run the project by typing the command:

通过键入以下命令运行项目:

npm run start

npm运行开始

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

在这里,您可以参考先前的故事来测试API:

  1. For authentication and authorization.

    用于身份验证和授权。

  2. For testing company and employee APIs

    用于测试公司和员工的API

结论(Conclusion:)

We have successfully created Restful APIs using Prisma.

我们已经使用Prisma成功创建了Restful API。

翻译自: https://medium.com/nonstopio/prisma-with-rest-pagination-authentication-and-authorization-d7ce02cab731

prisma orm

你可能感兴趣的:(prisma orm_具有REST的Prisma-身份验证和授权)