-
Notifications
You must be signed in to change notification settings - Fork 66
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
lib.NewRequestHandler removes boilerplate from api package #1682
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from some nits, LGTM but will leave to @dustmop to take a look at parts relevant to him.
But very smooth 🍸
// switch on HTTP verbs. I think we should use tricks like this that leverage | ||
// the gorilla/mux package until we get a better sense of how our API uses | ||
// HTTP verbs | ||
func handleRefRouteMethods(m *mux.Router, ae lib.APIEndpoint, f http.HandlerFunc, methods ...string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
api/api_test.go
Outdated
@@ -251,7 +251,7 @@ func TestServerReadOnlyRoutes(t *testing.T) { | |||
{"POST", "/registry/profile/new", 403}, | |||
{"POST", "/registry/profile/prove", 403}, | |||
{"GET", "/checkout/", 403}, | |||
{"GET", "/status/", 403}, | |||
// {"GET", "/status/", 403}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work with {"GET", "/status", 403},
ie remove the trailing /
as gorilla is strict about slashes by default.
// UnmarshalParams deserialzes a lib req params stuct pointer from an HTTP | ||
// request | ||
// | ||
// Deprecated: This is only exported for one-off handlers in the API package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
lib/http.go
Outdated
} | ||
|
||
if err := UnmarshalParams(r, p); err != nil { | ||
log.Debugw("unmarshal dataset save error", "err", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an odd message, maybe unmarshal request params error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation seems totally agreeable to me.
I have a suggestion for how to handle some of the outstanding questions, such as how to correlate endpoints to methods, and how to determine which http verb to use: 963e650
@@ -107,7 +107,7 @@ const ( | |||
// fsi endpoints | |||
|
|||
// AEStatus returns the filesystem dataset status | |||
AEStatus = APIEndpoint("/status/{path:.*}") | |||
AEStatus = APIEndpoint("/status") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean /status
cannot be used with a reference? That seems to contradict the unit test just above in api/fsi_test.go
. Also, though that's how it works currently, it's actually a bug that should be fixed, see https://github.com/qri-io/qri/blob/master/cmd/status.go#L70 and #1246.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can, but the route expansion is handled by handleRefRouteMethods
in api/api.go
where it registers all the variants, this basically just represents the "route prefix" as we used to carry around.
So for now it works pretty much as it used to, still contradicting #1246 and is a fix for another day/PR I guess.
Leveraging our new patterns to have lib begin to generate it's own request handlers
cf03f29
to
5ef1821
Compare
rework link params processing & add method-specific-and-ref-specific handler function
5ef1821
to
27c187c
Compare
building on ideas from #1650, this adds the first method where the HTTP handler is generated by package lib, but mapped to an endpoint by package api.
This PR is mainly to establish the patten & talk through repercussions. Right now this only works for formats where the response format is well known / singular.