nanoapi
Nano API Implementation in GO
TL;DR
The idea is to create a very simple API interface on top of standard router like the one shown below.
The implementation relies on top of generics, to make things really simple, as shown below.
nanoapi.HF("b", func(i string) (out time.Time, err error) {
out = time.Now()
return
})
http.ListenAndServe(":8080", nil)
Later on you call it as:
res, err = http.Get("http://localhost:8080/b")
if err != nil {
log.Printf("Err: " + err.Error())
t.Fatal()
}
Details
In case more control is required, method H (Handler) can be used with a nanoapi.C (C abstracts a Command) struct, like this:
nanoapi.H(&nanoapi.C[string, string]{
Name: "a",
F: func(i string) (out string, err error) {
out = "Got: " + i
return
},
Help: "A function",
})
Nano api will provide you some methods (in case you call nanoapi.Setup first):
-
__list: lists all available commands
-
__help/cmd: Provides you a JSON object with in, out format , cmd message and Help message (in case you use H to register CMD), like this:
{"name":"b","in":"","out":"0001-01-01T00:00:00Z","help":"Function b"}
Important
At this moment, no methods are bound to API - we want simple Registration is done directly to defaultMux - we want simple It only supports stdlib router - we want simple
Your contribution / feedback is welcome.