This example shows how to implement a REST API using NestJS and Prisma Client. It uses a SQLite database file with some initial dummy data which you can find at ./prisma/dev.db
. The example was bootstrapped using the NestJS CLI command nest new rest-nestjs
.
Download this example:
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/latest | tar -xz --strip=2 prisma-examples-latest/typescript/rest-nestjs
Install npm dependencies:
cd rest-nestjs
npm install
Note that this also generates Prisma Client JS into node_modules/@prisma/client
via a postinstall
hook of the @prisma/client
package from your package.json
.
Alternative: Clone the entire repo
Clone this repository:
git clone [email protected]:prisma/prisma-examples.git --depth=1
Install npm dependencies:
cd prisma-examples/typescript/rest-nestjs
npm install
npm run dev
The server is now running on http://localhost:3000
. You can now the API requests, e.g. http://localhost:3000/feed
.
You can access the REST API of the server using the following endpoints:
/post/:id
: Fetch a single post by itsid
/feed
: Fetch all published posts/filterPosts?searchString={searchString}
: Filter posts bytitle
orcontent
/post
: Create a new post- Body:
title: String
(required): The title of the postcontent: String
(optional): The content of the postauthorEmail: String
(required): The email of the user that creates the post
- Body:
/user
: Create a new user- Body:
email: String
(required): The email address of the username: String
(optional): The name of the user
- Body:
/publish/:id
: Publish a post by itsid
/post/:id
: Delete a post by itsid
- Check out the Prisma docs
- Share your feedback in the
prisma2
channel on the Prisma Slack - Create issues and ask questions on GitHub