Hacker News new | ask | show | jobs
by ta-run 1112 days ago
What I fail to understand is how the server interprets the query content/body; how does the server "apply" the "sql" query in the request to the resource? is there something similar to a gql resolver that you need to write?
1 comments

It's agnostic, the QUERY verb has nothing to do with the actual implementation, or the content encoding. You can use any content encoding for your query body, and you can resolve it any way you see fit.

In mine, I was just caching raw sql queries, so it was literally just text/sql encoding, the query in the body, some metadata in headers, and a sqlalchemy engine to execute the query.

It's basically a way to get around the non-idempotency of POST and URI limitations of GET.

Aha, got it. Thanks for the explanation.

So, the request content/body can have "non-sql-like" queries? can it be GraphQL? or even plain English? - of course, assuming that the server knows how to resolve the query.

Yep. This is valid

    QUERY /graphql
    Content-Type: text/graphql
    {too lazy to write valid gql}
so is this

    QUERY /elasticsearch
    Content-Type: application/json
    {"name": "alice"}
Even this

    QUERY /my-ai-image-gen
    Content-Type: text/plain
    Draw me a picture of a cat
It's entirely up to the software to decide how to handle the request.
Great, thank you!