-
Notifications
You must be signed in to change notification settings - Fork 17
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
feat: add next choice. refs #16 #25
Conversation
Hi @dianalin2 !! Thanks for the PR.! What about adding some validation to check the query params, as specified in #16 (comment) ? So, if the user specifies other parameters than those specified the endpoint should return a Bad Request explaining what are the expected params. A bonus would be to add a unit test to those scenarios. @GreenStage @zamariola any thoughts on that? |
Hey, @tiagostutz! Thanks for the response, that sounds great. So, it would return a Bad Request error if there are other parameters, correct? What if the |
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.
Extra inert information is harmless, as long as the necessary data is there and valid, no 400 should ever be returned.
Likewise, additional query params should just be ignored. Otherwise, we would be adding extra complexity to the project, making it a bit harder to maintain for no meaningful reason.
Most webservices follow this approach (try passing an extra query param on google, youtube, or Facebook).
Good job
internal/api/v1/routes.go
Outdated
} | ||
] | ||
}`) | ||
ctx.Data(http.StatusOK, "application/json", payload) |
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.
ctx.JSON(http.StatusOk, payload), in the future we're gonna have a struct and not []bytes.
(and then replace the mocked payload type from []byte to json.RawMessage, or ctx.JSON will base64 encode it)
Hi @GreenStage ! About the Google/Facebook example, it doesn't apply to all of their APIs. If you are sending those query params to the URL used in the browser, that's right. Maybe with some API's it may be true either. But there are some Google API's that the scenario is a bit different. Check those Google Classroom API requests: This request returns 200 with the payload:
This request with a non-existend query param returns 400 code with a detailed message:
Return Message:
This other request send an valid parameter
Return Message:
So, even though I think we should follow this approach for a more stable and predictable experience using the API, we could merge this PR here and open another issue to discuss that.! What do you think @GreenStage and @dianalin2 ? |
Cheers @tiagostutz , I fully agree with returning 400 when a valid param has a invalid value. Regarding,passing an unknow paramater key, the example you provided refers to google's conversion of their grpc API into HTTP, so I am resilient in considering it a good restful example. Note that grpc protocol requires a serialized schema, so it cant afford to have unknown properties in the buffer. Nevertheless, The mr is good-to-go by me 👍 |
Creates the endpoint for the next choice.