Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions internal/sbi/api_myapi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package sbi

import (
"net/http"

"github.com/gin-gonic/gin"
)

// getMyAPIRoute define las rutas de nuestro nuevo servicio "myapi".
// Tendrá al menos un GET y un POST, como pide el lab.
func (s *Server) getMyAPIRoute() []Route {
return []Route{
{
Name: "MyAPI GET info",
Method: http.MethodGet,
Pattern: "/",
APIFunc: func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"service": "myapi",
"status": "ok",
})
},
},
{
Name: "MyAPI POST echo",
Method: http.MethodPost,
Pattern: "/echo",
APIFunc: func(c *gin.Context) {
var req struct {
Message string `json:"message" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"})
return
}
c.JSON(http.StatusOK, gin.H{
"echo": req.Message,
})
},
},
}
}
3 changes: 3 additions & 0 deletions internal/sbi/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func newRouter(s *Server) *gin.Engine {
spyFamilyGroup := router.Group("/spyfamily")
applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute())

myapiGroup := router.Group("/myapi")
applyRoutes(myapiGroup, s.getMyAPIRoute())

return router
}

Expand Down
Loading