Crema is a Simple Go-Based RESTful API Framework originally written by Universitas Pertamina ICT teams to support its Microservices environment development. It is written in pure Go and completely free. Crema is now maintained by a small independent research and development team, and is also supported by Hexavara Foundation.
Playing with RESTful API using Crema is fun and easy
- Create HTTP routes
func main() {
server := crema.InitServer()
server.AddRoutes(http.MethodGet, "/hello", hello)
server.AddRoutes(http.MethodGet, "/users", crema.MakeGenericGetHandler(getUser))
crema.LogPrintf("[MAIN] Server is running, listening to port 8001 ....")
log.Fatal(http.ListenAndServe(":8001", server.Router))
}
- Create Handlers
func hello(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
}
func getUser(conditions map[string]string) (*sql.Rows, error) {
q := crema.Select().All().From("users")
return crema.ExecuteQuery(q.QueryString)
}
- Try it using cURL
$ curl http://localhost:8001/hello
Hello World!
$ curl http://localhost:8001/users
{"status":1,"message":"Success 200","data":[{"email":"[email protected]","id":16,"name":"John Doe"},{"email":"[email protected]","id":17,"name":"Bob"}]}
- A Gorilla Mux-based HTTP router
- Customizable generic request handler
- Simplified Data Access Object mechanism
- PostgreSQL and MySQL database driver
- Personalized system logger
- With a correctly configured Go toolchain:
$ go get github.com/gadp22/crema
- Import in your code
import "github.com/gadp22/crema"
How to set up your first project using Crema.
See here to see basic example to build a CRUD API.
See here to see further documentations.