Notes Display
Learn to create an API to read and render a note from the database.
We'll cover the following...
Reading a note
In this lesson, we are going to implement a route/API that shows the details of a note.
Let’s start by defining a new route in the routers/route.go
file.
Press + to interact
package routersimport ("beego_notes/controllers"beego "github.com/beego/beego/v2/server/web")func init() {beego.Router("/", &controllers.MainController{})beego.Router("/notes", &controllers.NotesController{}, "get:NotesIndex")beego.Router("/notes/new", &controllers.NotesController{}, "get:NotesNewForm")beego.Router("/notes", &controllers.NotesController{}, "post:NotesCreate")beego.Router("/notes/:id([0-9]+)", &controllers.NotesController{}, "get:NotesShow")}
Line 14: The route with the pattern /notes/:id([0-9]+)
uses the GET method to trigger the NotesShow()
action, where :id
is a placeholder for the note’s numerical ...