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

refactor(api): aligning our API with spec #1734

Merged
merged 1 commit into from
Apr 8, 2021
Merged

refactor(api): aligning our API with spec #1734

merged 1 commit into from
Apr 8, 2021

Conversation

Arqu
Copy link
Contributor

@Arqu Arqu commented Apr 1, 2021

Aiming to get us closer to the API spec contained in #1731, I've refactored some of the code to move to POST only, cleaned up the route definitions and rearranged most of the routes in the same order as in our tables. The main reason for rearranging is to make the follow up steps more explicit:

  • Which handler methods need to move into which handler
  • Highlight unfinished or missing routes
  • Highlight routes that are no longer needed or otherwise misplaced

I'll run a round of self commenting on the PR just to add some color to it. Looking for some input before diving into the code move.

@Arqu Arqu added API JSON API issues Breaking Change things that change existing API contracts. labels Apr 1, 2021
@Arqu Arqu requested review from b5, dustmop and ramfox April 1, 2021 20:40
@Arqu Arqu self-assigned this Apr 1, 2021
api/api.go Show resolved Hide resolved
api/api.go Outdated Show resolved Hide resolved
}

dsh := NewDatasetHandlers(s.Instance, cfg.API.ReadOnly)
// aggregate endpoints
m.Handle(lib.AEList.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "dataset.list"))).Methods(http.MethodPost, http.MethodGet)
m.Handle(lib.AEListRaw.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "dataset.listrawrefs"))).Methods(http.MethodPost, http.MethodGet)
m.Handle(lib.AEPeerList.String(), s.Middleware(dsh.PeerListHandler(lib.AEPeerList.String())))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also merge into AEList

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this "/peer/list"? It's still there in #1697.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this particular endpoint is not the list of peers, but instead the list of datasets you have from a specific peer. Which I believe would become /list w/ the filter=ramfox in the params

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes what @ramfox said.

  • /peer/list lists your peers
  • /list/{peer} lists datasets of a given peer and should be moved into list with the new filtering approach

api/api.go Outdated

// dataset endpoints
routeParams = newrefRouteParams(lib.AEWhatChanged, false, false, http.MethodGet, http.MethodPost)
handleRefRoute(m, routeParams, s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "fsi.whatchanged")))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the handleRefRoute mean that these routes include all the sugar which we should drop and lock to POST only. Only /ds/get should be an exception for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, yes.

api/api.go Outdated Show resolved Hide resolved
api/api.go Outdated
handleRefRoute(m, routeParams, s.Middleware(dsh.SaveHandler(lib.AESave.String())))
routeParams = newrefRouteParams(lib.AEPull, false, false, http.MethodPost, http.MethodPut)
handleRefRoute(m, routeParams, s.Middleware(dsh.PullHandler(lib.AEPull.NoTrailingSlash())))
routeParams = newrefRouteParams(lib.AEPush, false, false, http.MethodGet, http.MethodPost, http.MethodDelete)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Push should also move into dataset?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I believe that is correct.


// dataset endpoints
routeParams = newrefRouteParams(lib.AEWhatChanged, false, false, http.MethodGet, http.MethodPost)
handleRefRoute(m, routeParams, s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "fsi.whatchanged")))
routeParams = newrefRouteParams(lib.AEGet, false, true, http.MethodGet, http.MethodPost)
handleRefRoute(m, routeParams, s.Middleware(dsh.GetHandler(lib.AEGet.String())))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ds/log is still TODO

m.Handle(lib.AEHistory.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "log.history"))).Methods(http.MethodPost)
// TODO(aqru): clear up these endpoints up to spec

m.Handle(lib.AELog.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "log.history"))).Methods(http.MethodPost)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had a discussion around these, but I don't have all the details to spell them all out on how we will merge these/how they should behave/which we will just drop from the HTTP API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to #1730, rawlogbook and logbookssummary should be dropped from the API, because they're "hard-mode" only. Not totally sure about the other 2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe history will be the /log endpoint with filter=history (or selector=history, whatever language we choose)

api/api_test.go Show resolved Hide resolved
lib/fsi.go Outdated Show resolved Hide resolved
@ramfox ramfox mentioned this pull request Apr 1, 2021
29 tasks
Copy link
Contributor

@dustmop dustmop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments so far

lib/datasets.go Show resolved Hide resolved
}

dsh := NewDatasetHandlers(s.Instance, cfg.API.ReadOnly)
// aggregate endpoints
m.Handle(lib.AEList.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "dataset.list"))).Methods(http.MethodPost, http.MethodGet)
m.Handle(lib.AEListRaw.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "dataset.listrawrefs"))).Methods(http.MethodPost, http.MethodGet)
m.Handle(lib.AEPeerList.String(), s.Middleware(dsh.PeerListHandler(lib.AEPeerList.String())))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this "/peer/list"? It's still there in #1697.

api/api.go Outdated Show resolved Hide resolved
api/api.go Outdated Show resolved Hide resolved
api/api.go Outdated

// dataset endpoints
routeParams = newrefRouteParams(lib.AEWhatChanged, false, false, http.MethodGet, http.MethodPost)
handleRefRoute(m, routeParams, s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "fsi.whatchanged")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, yes.

m.Handle(lib.AEHistory.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "log.history"))).Methods(http.MethodPost)
// TODO(aqru): clear up these endpoints up to spec

m.Handle(lib.AELog.String(), s.Middleware(lib.NewHTTPRequestHandler(s.Instance, "log.history"))).Methods(http.MethodPost)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to #1730, rawlogbook and logbookssummary should be dropped from the API, because they're "hard-mode" only. Not totally sure about the other 2.

cmd/log.go Outdated Show resolved Hide resolved
lib/api.go Outdated Show resolved Hide resolved
lib/datasets.go Outdated
// "render": {AE??, "POST"},
"remove": {AERemove, "POST"},
"validate": {AEValidate, "POST"},
// "unpack": {AE??, "POST"},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AEUnpack

lib/fsi.go Outdated Show resolved Hide resolved
lib/log.go Outdated
Comment on lines 30 to 31
"history": {AELog, "POST"},
"entries": {AEEntries, "POST"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear here, I just made this name change from /logbook to /entries for clarify, but always intended it to be temporary until we adjust to the new spec. When we do our final refactor, /entries should be /log and /history should be removed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, and yeah I'll be keeping rebasing this as I'm trailing all the other changes.

@Arqu Arqu force-pushed the arqu/api_audit branch 2 times, most recently from 9f2e5bb to 9622a06 Compare April 6, 2021 13:54
@Arqu
Copy link
Contributor Author

Arqu commented Apr 6, 2021

Majority of the refactor is done and I would like to land this before making this PR not just a refactor but a big change in the logic of some remaining methods.

A list of remaining things:
- merge log <> history
- merge list <> list/peer
- clean up handleRefRoute
- align remaining routes in correct methods
- one more run through routes vs spec

@Arqu Arqu marked this pull request as ready for review April 7, 2021 12:03
@Arqu Arqu requested review from ramfox and dustmop April 7, 2021 12:03
@b5 b5 added this to the v0.10.0 milestone Apr 7, 2021
@Arqu
Copy link
Contributor Author

Arqu commented Apr 8, 2021

Quick observations from the current standing of the PR:

  • /remote/remove vs /ds/remove we currently have both I think
  • /peer/remove - this exists in the spec but not in code as far as I can see
  • /access/token - need to bring this one back seems to be lost in the rebases - only the API handler/route binding, code is there

@ramfox
Copy link
Member

ramfox commented Apr 8, 2021

hmmm re /peer/remove I'm not sure what this would do? Remove the peer from your peerstore? Otherwise, we already have the ability to disconnect.

/remote/remove and /ds/remove is tricky & i think clashes with two thought processes we have. On one hand, we specifically decided that we wanted our api to have qri remove --remote qri_remote & /remote?remote="qri_remote" when we first established removing from a remote. However, the way it's set up we switch on local vs remote at the api/cmd level. This means we would need a custom api handler function to control the flow here. Another option is combining these at the lib level. But then this opens up more questions about remote behavior, resolution, and how we separate out concerns, that we will come up against in the future when we open up the ability to do more behavior on a remote (saving, triggering runs, changing permissions).

I think the easiest thing to do rn would be to remove the remote behavior from the /ds/remove endpoint, punt the convo, separate the concerns completely, and have this discussion when we open up more remote behaviors.

@ramfox
Copy link
Member

ramfox commented Apr 8, 2021

This is so lovely. Noticed that you refactored away from sql.QueryHandler, but that the api/sql.go & api/sql_test.go files wasn't removed.

Copy link
Member

@b5 b5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arqu this is looking great. To avoid further rebasing I vote we merge this now & do follow-ups for any subsequent fixes

@Arqu Arqu merged commit 5821567 into master Apr 8, 2021
@Arqu Arqu deleted the arqu/api_audit branch April 8, 2021 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API JSON API issues Breaking Change things that change existing API contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants