Skip to main content
Version: v2.0

Create a blog project

Steps for creating a sample blog project.

Let's create a project which includes a Prisma schema(mongo.prisma) for creating a blog app using mongodb.

  1. Create a project using Godspeed CLI with below command:
godspeed create blog-app --from-example mongo-as-prisma # blog-app is the name of the app

Checkout other examples

In this sample project, we have utilized a MongoDB database, but you have the flexibility to choose any other database that Prisma supports and that meets your requirements MySQL, PostgreSQL etc

Framework will give you below folder structure.

    .
├── src
├── datasources
│ ├── types
│ | └── prisma.ts
| |
│ └── mongo.prisma

├── events
| |
│ └── helloworld.yaml
|
├── eventsources
│ ├── types
│ | └── express.ts
| |
│ └── http.yaml
|
└── functions
|
└── helloworld.yaml
  1. Navigate to you project folder
cd blog-app
  1. Open the project in vscode using below command:
code .
  1. Now to setup your database please follow the steps provided in README.md file of your blog-app project.

Prisma supports wide range of databases

Prisma provides a unified and versatile database experience, enabling you to connect to diverse databases through a single schema definition. This ensures a consistent schema for interacting with various databases and generates a unified API, streamlining development for flexibility and ease. Whether you opt for MySQL, PostgreSQL, SQLite, or other supported databases, Prisma's unified approach simplifies both database management and application development.

  1. Open terminal in vscode and enter the below command
godspeed prisma prepare

This command will generate the prisma client and will sync the database with prisma schema

  1. 3000 is the default port number,if you want to provide your custom port number, you can modify the port number from "./src/eventsources/http.yaml"
type: express
port: 3000
  1. Now to generate the CRUD API'S enter the below command
godspeed gen-crud-api

This command will generate the crud apis based on the sample prisma schema provided at ./src/datasources/mongo.prisma

Command generates the below respective folders and files in the Events and Functions.

    .
├── src
├── datasources
│ ├── types
| └── prisma.ts
| |
│ └── mongo.prisma
|
├── events
| ├── post.yaml
│ └── user.yaml
|
├── eventsources
│ ├── types
| └── express.ts
| |
│ └── http.yaml
|
└── functions/com/biz/mongo
├── post
| ├── create.yaml
| ├── delete.yaml
| ├── one.yaml
| ├── search.yaml
| └── update.yaml
|
└── user
├── create.yaml
├── delete.yaml
├── one.yaml
├── search.yaml
└── update.yaml
  1. Run godspeed serve to start the development server.
godspeed serve
  1. Go to http://localhost:3000/api-docs to see the API endpoints in the swagger.
swagger spec default
  1. Create a user in the Mongodb by giving the proper request body to the post API in the swagger and execute it.swagger mongo user
  1. An appropriate response will be returned on successful execution.swagger response

Voila! Your API backend is up and running. You can use Postman or swagger to test your API's.

Happy building with Godspeed!