minimal_api is a lightweight and high-performance microframework written in Go, designed to facilitate the creation of minimalist APIs. Its design is inspired by frameworks like Flask and FastAPI, but built to leverage the speed of fasthttp
.
This project combines simplicity and efficiency, offering an easy experience for developers seeking speed and flexibility in their applications.
- Ultra-fast: Built on
fasthttp
, it offers superior performance for handling HTTP requests. - Clean and simple API: Define routes, middlewares, and handlers intuitively.
- Middlewares: Support for global and route-specific middlewares.
- Graceful shutdown: Proper handling of system signals to safely stop the server.
- Modular code: Separation of responsibilities between the server and the router to facilitate scalability.
-
Clone the repository:
git clone https://github.com/pol-cova/minimal_api.git cd minimal_api
-
Install dependencies:
Make sure you have Go 1.18 or higher installed and run:
go mod tidy
-
Run the server:
go run main.go
This example shows how to use minimal_api
to set up a simple server with routes and middlewares:
package main
import (
"github.com/pol-cova/minimal_api/mapi"
)
func main() {
app := mapi.NewApp()
app.UseLogger()
app.GET("/api", func(c *mapi.Context) {
c.Response.SetBodyString("Hello, from minimal API")
})
app.POST("/api", func(c *mapi.Context) {
c.Response.SetBodyString("Hello, from POST")
})
app.Run("127.0.0.1:5000")
}
- Visit http://localhost:8080/api to see the welcome message.
- Visit http://localhost:8080/api to test a POST route.
The server is designed to shut down safely when it receives an interrupt signal.
-
Start the server normally:
go run main.go
-
Stop the server by pressing
Ctrl+C
in the terminal. You will see a message like:Shutting down server... Server gracefully stopped
minimal_api/
|--mapi/
├── app.go // Main file to start the server
├── server.go // Main server logic
├── router.go // Route and middleware management
├── context.go // Request and response context
├── response.go // HTTP response handling
├── request.go // HTTP request handling
├── logger.go // Request logging middleware
|--middleware.go // Middleware definitions
|--template.go // Template for server-side HTML
|--static.go // Static file handling
├── go.mod // Project dependencies
├── go.sum // Dependency hashes
- minicli: Command-line tool to generate projects and control the server.
- Documentation: Improve documentation and examples to facilitate API usage.
- Performance: Optimize server performance and efficiency.
You are welcome to contribute! Here are some ways to do so:
- Report bugs: Open an issue for problems or questions.
- Improve the code: Submit a pull request with new features or fixes.
- Document: Help improve the documentation with additional examples or guides.
This project is licensed under the MIT License. See the LICENSE file for more information.
If you need help, feel free to create an issue in the repository or contact me directly. Thank you for your interest in minimal_api! Contact: polc394@gmail.com