Getting Started
- Create a Project
- Start the Server
- Inspect the Default Routes
- Add Your First Endpoint
- Verify the Result
- Next Steps
This tutorial starts with a new PrismGo application, runs the HTTP server, and adds a JSON endpoint.
Create a Project
Install the installer:
go install github.com/prismgo/installer/cmd/prismgo@latestCreate the application:
prismgo new hello-prism
cd hello-prismIf you already have the installer, start with prismgo new.
Start the Server
The entry point of a new app is main.go. It creates bootstrap.NewApplication() and passes CLI arguments to the PrismGo Console Kernel:
func main() {
app := bootstrap.NewApplication()
if err := app.HandleCommand(context.Background(), os.Args); err != nil {
console.Exit(err.Error())
}
}Start the HTTP server:
go run . serveThe default listen address comes from .env:
SERVER_HOST=127.0.0.1
SERVER_PORT=8080Call the health endpoint:
curl http://127.0.0.1:8080/api/healthYou should see:
{"status":"ok"}Inspect the Default Routes
In another terminal, run:
go run . route:listA new project registers /api/health and /api by default. The route declarations live in routes/api.go and are mounted through app/http/register.go.
Add Your First Endpoint
Open routes/api.go and add a route inside the Register function:
route.Get("/api/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})The full shape should look like this:
func Register(app Dependencies) {
route.Get("/api/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
})
route.Get("/api/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"message": "pong"})
})
if app.WelcomeController != nil {
route.Get("/api", app.WelcomeController.Show)
}
}If go run . serve is still running, stop and restart it:
go run . serveVerify the Result
Call the new endpoint:
curl http://127.0.0.1:8080/api/pingYou should see:
{"message":"pong"}Inspect the route list again:
go run . route:list --path=pingNext Steps
- Use the generator commands to create controllers, models, migrations, and jobs.
- Read Routing for groups, named routes, resource routes, and throttling.
- Read HTTP Server to configure ports, timeouts, proxies, and graceful restarts.
- Read Database and Queue to add persistence and background work.