First Route, API, and HTML Response
Explore how to create a simple GET API route in Beego, link it to a controller handler, and render an HTML response using templates. Understand route definition, controller functions, and template integration to build responsive web pages with Beego.
We'll cover the following...
In this lesson, we will create a simple API that will be routed to a controller function, and a simple HTML template will be rendered as a response.
Defining the route
Let’s create a new API called GET /hello. All the APIs are listed in the file routers/router.go. We will add our API here and map it to its handler, a controller function.
Line 11: A new route is created. The beego.Router() function is used to route the /hello API to the MainController controller. The handler function is Hello() for the HTTP method GET. ...