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

Full query string helpers #1604

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

divarvel
Copy link
Contributor

@divarvel divarvel commented Aug 28, 2022

The goal of this PR is to adress a use-case that is not currently covered by servant: query strings with dynamic parameter names.

QueryParam and its friends are super useful, but extract the parameter name from a type-level string, so while this is useful in many cases, it cannot cover every use-case. A typical use-case would be implementing a search filter where filters are not static and can't be enumerated ahead of time.

I'll propose two helpers, directly derived from a use case that came up at work:

  • one is an escape hatch that extracts the whole query string as a [(ByteString, Maybe ByteString)] value. It cannot fail and provides raw access to the query string: QueryString :> Get '[JSON] [Book].
    This was the first version that i implemented for my concrete use-case at work, to get things going.
  • the other one is a bit more constrained and implements a pattern commonly known as deep objects. It builds upon the convention of using [] for a list of parameters: books?filter[search]=value&filter[author][name]=value. The corresponding type would be DeepQuery "filter" BookQuery :> Get '[JSON] [Book].
    This is based on what's currently used for my use-case at work.

Raw query string capture

  • Servant.API
  • Servant.Server
  • Servant.Server Specs
  • Servant.Server Docs
  • Servant.Client
  • Servant.Client Specs
  • Servant.Client Docs

Deep object query parsing

  • Servant.API
  • Servant.Server
  • Servant.Server Specs
  • Servant.Server Docs
  • Servant.Client
  • Servant.Client Specs
  • Servant.Client Docs

@tchoutri
Copy link
Contributor

Considering the limitations of what we already have, these additions are most welcome. Ping me if you ever want to pair on a Cookbook addition for this.

@divarvel divarvel force-pushed the full-query-string-helpers branch from 53359cb to fdf3bea Compare October 14, 2022 13:07
@divarvel divarvel force-pushed the full-query-string-helpers branch from fdf3bea to e350e76 Compare December 6, 2022 15:48
@divarvel divarvel force-pushed the full-query-string-helpers branch from e350e76 to 1ae85d1 Compare December 15, 2022 15:31
@divarvel
Copy link
Contributor Author

I'm not using haskell at work any more and I don't have time to revive this PR myself, but I still think it's a worthwhile addition to servant and am available to help anyone who wants to get it over the finish line.

@divarvel divarvel force-pushed the full-query-string-helpers branch 2 times, most recently from d387119 to 8dec489 Compare April 23, 2024 18:18
@divarvel divarvel marked this pull request as ready for review April 23, 2024 18:30
@divarvel divarvel force-pushed the full-query-string-helpers branch from 8dec489 to bcbd3d2 Compare April 23, 2024 18:45
@tchoutri tchoutri merged commit 907245a into haskell-servant:master Apr 23, 2024
2 checks passed
@tchoutri
Copy link
Contributor

🎉 🎉 🎉 🎉

@ysangkok ysangkok mentioned this pull request Jun 22, 2024
@ysangkok
Copy link
Contributor

@tchoutri Since this PR broke backwards compatibility, we need to do a major version bump. Do we do that now, or just before the release? The advantage of doing it now is that then we don't have to remember that this PR changed the interface.

@tchoutri
Copy link
Contributor

@ysangkok yep let's do it right away. If you can't do it in the next 10 hours I'll do it in my morning. :)

fendor added a commit to smucclaw/dsl that referenced this pull request Jul 5, 2024
In order for LLMs to interact with the REST API (which is on the goals
of the so-called LAG project), we need to provide an openapi3 compatible
API.
We do this by depending on 'servant-openapi3', and add appropriate
instances for the servant REST API.

Due to some issues, it seems like it is impossible (or very difficult),
to make custom gpts invoke REST endpoints with JSON bodies... So, for
now we simply send all parameters via Query Parameters.
Until the next servant release, we have to explicitly name all
query parameters. See
haskell-servant/servant#1604 for the PR that we
are interested in.
fendor added a commit to smucclaw/dsl that referenced this pull request Jul 5, 2024
In order for LLMs to interact with the REST API (which is on the goals
of the so-called LAG project), we need to provide an openapi3 compatible
API.
We do this by depending on 'servant-openapi3', and add appropriate
instances for the servant REST API.

Due to some issues, it seems like it is impossible (or very difficult),
to make custom gpts invoke REST endpoints with JSON bodies... So, for
now we simply send all parameters via Query Parameters.
Until the next servant release, we have to explicitly name all
query parameters. See
haskell-servant/servant#1604 for the PR that we
are interested in.
fendor added a commit to smucclaw/dsl that referenced this pull request Jul 5, 2024
In order for LLMs to interact with the REST API (which is on the goals
of the so-called LAG project), we need to provide an openapi3 compatible
API.
We do this by depending on 'servant-openapi3', and add appropriate
instances for the servant REST API.

Due to some issues, it seems like it is impossible (or very difficult),
to make custom gpts invoke REST endpoints with JSON bodies... So, for
now we simply send all parameters via Query Parameters.
Until the next servant release, we have to explicitly name all
query parameters. See
haskell-servant/servant#1604 for the PR that we
are interested in.
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.

3 participants