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

implements POST /query #612

Merged
merged 2 commits into from Feb 22, 2024
Merged

implements POST /query #612

merged 2 commits into from Feb 22, 2024

Conversation

brunocalza
Copy link
Collaborator

@brunocalza brunocalza commented Feb 21, 2024

Summary

Implements the POST /query spec defined at tablelandnetwork/docs#188

Working example on staging

curl -v --json '{"statement": "SELECT * FROM system_txn_receipts LIMIT 1"}' https://staging.tableland.network/api/v1/query

cc @dtbuchholz

Context

We're adding support for POST /query so queries can be sent via body request without the need of encoding the URL.

Implementation overview

Generates the code based on a new spec and implements the controller in a similar way to GET /query.

Signed-off-by: Bruno Calza <brunoangelicalza@gmail.com>
Makefile Outdated
@@ -80,7 +80,7 @@ lint:
.PHONY: lint

# OpenAPI
SPEC_URL=https://raw.githubusercontent.com/tablelandnetwork/docs/main/specs/validator/tableland-openapi-spec.yaml
SPEC_URL=https://raw.githubusercontent.com/tablelandnetwork/docs/bcalza/postquery/specs/validator/tableland-openapi-spec.yaml
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

points to the new spec. gotta change this before merge

@@ -265,6 +270,65 @@ func (c *Controller) GetTableQuery(rw http.ResponseWriter, r *http.Request) {
_, _ = rw.Write(formatted)
}

// PostTableQuery handles the POST /query call.
func (c *Controller) PostTableQuery(rw http.ResponseWriter, r *http.Request) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

new handler for POST /query

@@ -61,6 +61,10 @@ func configureAPIV1Routes(
userCtrl.GetTableQuery,
[]mux.MiddlewareFunc{middlewares.WithLogging, rateLim},
},
"QueryByStatementPost": {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adds new route

return fmt.Errorf("get method: %s", err)
}

for _, method := range methods {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

connects the route with the handler

@brunocalza brunocalza marked this pull request as ready for review February 21, 2024 17:38
@@ -256,6 +256,11 @@ func (c *Controller) GetTableQuery(rw http.ResponseWriter, r *http.Request) {
return
}

if len(formatted) == 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here it is @sanderpick

sanderpick
sanderpick previously approved these changes Feb 21, 2024
Copy link
Member

@sanderpick sanderpick left a comment

Choose a reason for hiding this comment

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

Lgtm!

avichalp
avichalp previously approved these changes Feb 22, 2024
Copy link
Collaborator

@avichalp avichalp left a comment

Choose a reason for hiding this comment

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

looks good!

Signed-off-by: Bruno Calza <brunoangelicalza@gmail.com>
@brunocalza brunocalza dismissed stale reviews from avichalp and sanderpick via 4166d3e February 22, 2024 14:54
@brunocalza brunocalza merged commit e037c20 into main Feb 22, 2024
5 checks passed
@brunocalza brunocalza deleted the bcalza/postquery branch February 22, 2024 15:03
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

Successfully merging this pull request may close these issues.

None yet

3 participants