An Oauth2 library for Clojure.
Calling an API is often a study in incidental complexity
Oh, what a tangled web we weave.
-- Sir Walter Scott
Making a request is easy - clj-http
.
But there is a lot to think about:
Despite this, web APIs are often described as easy. Companies like to pretend it's easy and users like to imagine that it's easy. Few people talk about the hard parts. This situation often ends with frustration and failure.
A library! Generated code from the webservice description document (A big JSON file). Oauth2 authentication.
Why do we need a new library? Existing libraries don't exist for Google APIs, and are not flexible enough to work with multiple providers.
Makes consuming the API a pleasure! I can use my IDE features like "help" and "autocomplete" to quickly make requests with confidence that I got them right.
There is value in having everything be data, and we can have both.
Automatically releasing schema changes would be nice to do in the future.
Oauth2
Credential lookup (looks for secret.json etc... is there a way to encourage encrypting credentials?)
There's already a good throttling library (but does it allow rate maximization)?
There's a retry library, is it enough?
Exceptions vs Errors. I strongly encourage using Exceptions. Doing so frees us to expect data as the return value, rather than a response that requires interpretation.
Originally I chose to follow the api organization as closely as possible, but upon reflection changed it to better collect resources:
happygapi.youtube.videos/list$
vs happygapi.youtube/videos-list
vs happygapi.youtube/videos$list
list
, get
etc.I originally chose to pass auth to every call, the proper functional choice. But upon reflection I changed it such that authentication happens as a side effect. This is more convenient, and if users don't want it they can assemble the middleware differently.
HappyAPI is now primarily an Oauth2 library, the code generation is in another project (happyapi.google).
Previously there were default scopes, but now there are no default scopes.
These seem like they would be helpful (future work).
Yes, that's how most other function works.
Generated code uses positional args, but everything gets routed through a request
function that takes a big map.
So if you prefer that style, you can use that instead.
Future work.
https://github.com/drone29a/clj-oauth https://github.com/sharetribe/aws-sig4
Question: how to control arg checking (if at all?), maybe leave that up to users? Maybe follow Malli convention (or spec) Idea:
(defn strict! []
(alter-var-root #'api-request
(fn [_prev]
(wrap-check-args-or-something??))))
We need a schema explorer experience - is this another case of summarize?
Major providers are inconsistent. Providing config for urls is useful, users just need to add their id/secret.
Figure out a way to run tests (at least some of them) in CI.
Make it ClojureScript compatible.
Generated code currently requests more scopes than are really necessary :( I think you just need any of the scopes? not all?
Numbers should be coerced to numbers based on the json schema for responses.
Can we provide secure options for secret and token storage?
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |