Home
Softono
fastify-prisma-rest-api

fastify-prisma-rest-api

Open source TypeScript
223
Stars
63
Forks
1
Issues
2
Watchers
3 years
Last Commit

About fastify-prisma-rest-api

fastify-prisma-rest-api is a tutorial project demonstrating how to build a REST API using Fastify, Prisma, Zod, Swagger, and TypeScript. The application supports user creation, login, and listing, as well as product creation and listing. It includes request and response validation with Zod, authentication using fastify-jwt, and auto-generated API documentation via Swagger. The project is intended as a learning resource, accompanying a video walkthrough that covers bootstrapping the Fastify instance, setting up Prisma, implementing authentication, and creating product endpoints. Testing is demonstrated using Node Tap, fastify.inject, faker-js for fake data, and ts-mock-imports for mocking. The test suite covers end-to-end API testing, HTTP request injection, function mocking, and working with a dedicated test database. The project requires PostgreSQL or MySQL and is suitable for developers learning to combine Fastify with Prisma for type-safe backend development.

Platforms

Web Self-hosted

Languages

TypeScript

Build a REST API with Fastify & Prisma

Video: https://youtu.be/LMoMHP44-xM

What are we using?

  • Fastify - Web server
  • Prisma - Database ORM
  • Zod - Request and response validation
  • Swagger - API docs
  • TypeScript - Types & other cool stuff

What you will need

Features

  • Create a user
  • Login
  • List users
  • Create a product
  • List products
  • Authentication
  • Request & response validation
  • Swagger docs

Video structure

  1. Demonstration
  2. Code walk-through
  3. Bootstrap application
    • Setup Prisma
    • Create Fastify instance
  4. Create user
    • Hash password
  5. List users
  6. Login
    • fastify-jwt setup
  7. Create product
  8. List products

Testing

What are we testing with?

What will I learn?

  • How to test your API end-to-end
  • How to inject http requests to your Fastify application
  • How to mock function calls
  • How to test with a test database

Where can I learn more about testing Fastify?