Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Add HTTP API v1 ("Hrana over HTTP") #305

Merged
merged 3 commits into from
Mar 28, 2023
Merged

Add HTTP API v1 ("Hrana over HTTP") #305

merged 3 commits into from
Mar 28, 2023

Conversation

honzasp
Copy link
Contributor

@honzasp honzasp commented Mar 24, 2023

We need to update the HTTP API to support batches and to fix some issues (such as encoding of types). Instead of coming up with a new API, let's just reuse the Hrana structures and semantics. In effect, the new version of the HTTP API is "Hrana over HTTP".

This is needed for the new generation of the client libraries.

@honzasp honzasp requested a review from MarinPostma March 24, 2023 21:19
@honzasp honzasp marked this pull request as ready for review March 27, 2023 07:46
Copy link
Collaborator

@MarinPostma MarinPostma left a comment

Choose a reason for hiding this comment

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

@honzasp
I tried executing: echo '{ "stmt": {"sql": "select * from test", "want_rows": true }}' | http post "127.0.0.1:8080/v1/execute"

The returned error is a 500, and gets logged in the logs:

2023-03-28T11:46:36.206182Z  INFO sqld::http: got request: POST /v1/execute
2023-03-28T11:46:36.206974Z ERROR tower_http::trace::on_failure: response failed classification=Status code: 500 Internal Server Error latency=0 ms

I am not sure this is adequate, and further error categorization should probably be performed

StmtError::TransactionTimeout | StmtError::TransactionBusy => {
hyper::StatusCode::SERVICE_UNAVAILABLE
}
StmtError::SqliteError { .. } => hyper::StatusCode::INTERNAL_SERVER_ERROR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Uhm regarding my comment before: I think this is the culprit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What HTTP status would be more appropriate? The error response includes a detailed message and will soon include the error code, the HTTP status is not very important.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was just surprised because it came up in the logs as an internal error, which leads me to believe that there is something broken, although everything is fine, and this is simply a user error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, then perhaps we should map all errors to HTTP status 400?

Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure
let's start with that and work on the error story later

@MarinPostma
Copy link
Collaborator

bors merge

@bors
Copy link
Contributor

bors bot commented Mar 28, 2023

Build succeeded:

@bors bors bot merged commit fb8b3c2 into libsql:main Mar 28, 2023
@honzasp honzasp deleted the http-v1 branch May 11, 2023 09:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants