noun, plural o·ka·pis, (especially collectively) o·ka·pi
- An African mammal, Okapia johnstoni, closely related to and resembling the giraffe, but smaller and with a much shorter neck.
- A small framework for (OK) composable API clients.
- Transparent error handling
- Flexible encoding / decoding
- Configurable, with sensible defaults
- Adheres to standard "net/http" interfaces
The Okapi client was desinged to be wrapped inside various helper structs, though it still can be used without any additional structs or fields.
type films struct {
client *okapi.Client
}
func Films(client *okapi.Client) *films {
return &films{client}
}
func (c *films) Get(name string) (*FilmsResponse, error) {
var res FilmsResponse
opts := &okapi.QueryOptions{
Params: map[string]string{
"search": name,
},
Out: &res,
}
if _, err := c.client.Get("/api/films/", opts); err != nil {
return nil, err
}
return &res, nil
}
Using the client:
func main() {
client, _ := okapi.NewClient(&okapi.Config{
Address: BASE_URL,
})
res, _ := Films(client).Get("Dune")
}
For a complete example implementation, see examples/starwars
Okapi is available under the terms of the MIT License.