APIEasy is a lightweight web framework for Go that simplifies the creation and handling of HTTP requests. It provides a convenient router and context for building robust web applications with minimal boilerplate code.
- HTTP Request Handling: Easily define routes and handle HTTP methods.
- JSON Response: Simplified methods for returning JSON responses with customizable status codes.
- Flexible Routing: Supports GET, POST, PUT, DELETE, and other HTTP methods.
- Middleware Support: Extendable middleware for additional request processing.
- Error Handling: Built-in mechanisms for handling errors and status codes.
To use APIEasy in your Go project, follow these steps:
-
Install Go (if not already installed): https://golang.org/doc/install
-
Create a new Go module (if not already created):
go mod init myapp
-
Install APIEasy:
go get github.com/Webblurt/apieasy
Example Usage Here's a basic example of setting up and running an HTTP server using APIEasy:
```golang
package main
import (
"github.com/Webblurt/apieasy"
)
func main() {
router := apieasy.NewRouter(":8080")
router.Handle("GET", "/hello", func(ctx *apieasy.Context) {
ctx.SetStatus(apieasy.OK, "Hello, World!", nil)
})
router.Handle("POST", "/api/data", func(ctx *apieasy.Context) {
data := struct {
Message string `json:"message"`
}{
Message: "Data received successfully",
}
ctx.JSON(apieasy.OK, data)
})
if err := router.Run(); err != nil {
panic(err)
}
}
```
Routes and handlers are added using the Handle method of the router. Handlers receive a Context object that contains information about the current request and methods to set the response status and message.
- APIEasy supports custom HTTP statuses and provides a convenient interface for request handling.
- Use SetStatus to set the response status and message within a handler.
- Visit the Go documentation for more information on the standard library.
If you have suggestions for improvements or find a bug, please open an issue on GitHub or submit a pull request. Contributions are welcome!
APIEasy is licensed under the MIT License. See the LICENSE file for more information.