forked from pocketbase/pocketbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pocketbase#1233] added health API endpoint
- Loading branch information
1 parent
506bfca
commit 5c899a4
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package apis | ||
|
||
import ( | ||
"github.com/labstack/echo/v5" | ||
"github.com/pocketbase/pocketbase/core" | ||
"net/http" | ||
) | ||
|
||
// bindHealthApi registers the health api endpoint. | ||
func bindHealthApi(app core.App, rg *echo.Group) { | ||
api := healthApi{app: app} | ||
|
||
subGroup := rg.Group("/health") | ||
subGroup.GET("", api.healthCheck) | ||
} | ||
|
||
type healthApi struct { | ||
app core.App | ||
} | ||
|
||
// healthCheck returns a 200 OK response if the server is healthy. | ||
func (api *healthApi) healthCheck(c echo.Context) error { | ||
payload := map[string]any{ | ||
"code": http.StatusOK, | ||
"message": "API is healthy.", | ||
} | ||
return c.JSON(http.StatusOK, payload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package apis_test | ||
|
||
import ( | ||
"github.com/pocketbase/pocketbase/tests" | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestHealthAPI(t *testing.T) { | ||
scenarios := []tests.ApiScenario{ | ||
{ | ||
Name: "health status returns 200", | ||
Method: http.MethodGet, | ||
Url: "/api/health", | ||
ExpectedStatus: 200, | ||
ExpectedContent: []string{ | ||
`"code":200`, | ||
}, | ||
}, | ||
} | ||
|
||
for _, scenario := range scenarios { | ||
scenario.Test(t) | ||
} | ||
} |