Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api list #130

Closed
awb99 opened this issue Jan 18, 2022 · 7 comments
Closed

api list #130

awb99 opened this issue Jan 18, 2022 · 7 comments

Comments

@awb99
Copy link

awb99 commented Jan 18, 2022

Thanks for the amazing martian library!
Its really an amazing design. Rest apis on the first look seem to be all the same.
But on a second look, they all have very small differences.
This customization is not easy to get done.
Martian solves it. Great design!

Now to my point: It would be great to have a list of publicly available pis that either bring open-api specs,
or to have a resource where apis that dont support open-api are fully speced.

If we could gradually build a list of many apis, then it would be much easier to do rest-apis in clojure.
I am pretty sure that there are already many of such speced apis out there.
Perhaps we could add them to a wiki?

@oliyh
Copy link
Owner

oliyh commented Jan 18, 2022

Hello,

Thank you for your kind words! There are already lists like https://github.com/public-apis/public-apis so I wouldn't be surprised if someone had already done it, needs a bit of searching however. Probably makes sense as its own list, and I would be happy to link to it from martian documentation.

Cheers

@awb99
Copy link
Author

awb99 commented Jan 18, 2022

I have written a library that can be used to authorize apis that need oauth2 tokens. I am currently converting the rest apis to martian. I have implemented github google xero. I will post a link once I am done converting.

@awb99
Copy link
Author

awb99 commented Jan 18, 2022

Some comments after using martian for a few days:

  1. It is hard to find out if a rest api supports discovery with swagger/openid. This is not that something is mentioned in most api documents that i found.

  2. Many openid connect providers have discoverable apis. Are they the same as openid/swagger specs? Seems to be a differwnt standard.. But perhaps it is the same?

  3. When specing an api it would be nice to have a way to make requests when all specs are just s/Any and then infer the specs from actual api requests. I guess we could write an interceptor that does that.

  4. Is it possible to have the api specs in edn files? This would make them more extendable. Also we could create a spec from a discoverable api endpoint once and then save it to edn. This way it can be easily extended at runtime.

@awb99
Copy link
Author

awb99 commented Jan 19, 2022

rest apis that work with oauth2 and martian: https://github.com/pink-gorilla/webly/tree/master/oauth2/src/modular/rest/martian
supports google, github, xero.

examples how to use the rest calls:
https://github.com/pink-gorilla/webly/tree/master/demo-rest/src/rest

What I dont like so much:
https://github.com/pink-gorilla/webly/blob/master/demo-rest/src/rest/google.clj
google has multiple api endpoint roots. I did add 3 google related martian "connection" exports.
They use the same oauth token store. But they just have different endpoint roots.

the xero web api uses two custom header interceptors (on top of the oauth token header).
a tenant-id header, which I create once (sort of a company with which to work). This works niceyl.
But then the query-api allows to search for changed data since a date. And for this interceptor
I did not manage to use a field from the request call.
https://github.com/pink-gorilla/webly/blob/master/oauth2/src/modular/rest/martian/xero.clj

@awb99
Copy link
Author

awb99 commented Jan 19, 2022

How can I rewrite this header-interceptor so that it
sets the "If-Modified-Since" header based on a parameter :modified-since

 (->> (martian/response-for t :invoice-list-since 
                                   {:modified-since "2022-01-01T00:00:00"
                                    :where "(Type == \"ACCREC\")"       
                                    :page 1})
            :body
            :Invoices
            print-invoices)

(defn add-modified-since-header [dt]
  {:name ::add-modified-since-header
   :enter (fn [ctx]
            (assoc-in ctx
                      [:request :headers "If-Modified-Since"]
                      dt))})

 {:route-name :invoice-list-since
    :summary "list invoices modified-since"
    :method :get
    :path-parts ["/api.xro/2.0/Invoices/"]
    :query-schema {s/Any s/Any}
    :produces ["application/json"]
    :consumes ["application/json"]
    :interceptors [(add-modified-since-header "2022-01-01T00:00:00")]}

@awb99
Copy link
Author

awb99 commented Jan 23, 2022

Any idea on my interceptor issue? Thanks

@oliyh
Copy link
Owner

oliyh commented Jan 25, 2022

Hi,

The ctx contains a key :params which contain the parameters passed to the martian call. You can use that to find your :modified-since value.

e.g.

(def add-modified-since-header
  {:name ::add-modified-since-header
   :enter (fn [ctx]
            (assoc-in ctx
                      [:request :headers "If-Modified-Since"]
                      (get-in ctx [:params :modified-since])))})

We have strayed a bit from the original issue topic of api lists, I will close this issue but feel free to open another one to deal with a particular topic, thanks for your feedback.

Cheers

@oliyh oliyh closed this as completed Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants