Skip to content

Commit

Permalink
Support getting /@querystring vocabs in context (#1704)
Browse files Browse the repository at this point in the history
* Support getting /@querystring vocabs in context

* changelog

* Add test, update docs

* Update docs/source/endpoints/querystring.md

Co-authored-by: Steve Piercy <web@stevepiercy.com>

---------

Co-authored-by: Víctor Fernández de Alba <sneridagh@gmail.com>
Co-authored-by: Steve Piercy <web@stevepiercy.com>
Co-authored-by: Timo Stollenwerk <tisto@users.noreply.github.com>
  • Loading branch information
4 people committed Sep 21, 2023
1 parent 4398aad commit 8e2786a
Show file tree
Hide file tree
Showing 7 changed files with 1,767 additions and 18 deletions.
30 changes: 13 additions & 17 deletions docs/source/endpoints/querystring.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
---
myst:
html_meta:
"description": "The @querystring endpoint returns the querystring configuration of plone.app.querystring."
"property=og:description": "The @querystring endpoint returns the querystring configuration of plone.app.querystring."
"description": "The @querystring endpoint returns metadata about available query operations."
"property=og:description": "The @querystring endpoint returns metadata about available query operations."
"property=og:title": "Querystring"
"keywords": "Plone, plone.restapi, REST, API, Querystring"
---

# Querystring

The `@querystring` endpoint returns the `querystring` configuration of `plone.app.querystring`.
The `@querystring` endpoint returns metadata about the query operations that can be performed using the [`@querystringsearch`](querystringsearch) endpoint.

Instead of simply exposing the `querystring` related `field` and `operation` entries from the registry, it serializes them in the same way that `p.a.querystring` does in its `@@querybuilderjsonconfig` view.
The results include all of the indexes that can be queried, along with metadata about each index.
The top-level `indexes` property includes all indexes, and the top-level `sortable_indexes` property includes only the indexes that can be used to sort.

This form is structured in a more convenient way for frontends to process:
Each index result includes a list of the query operations that can be performed on that index.
The `operations` property contains the list of operations as dotted names.
The `operators` property contains additional metadata about each operation.

- *Vocabularies* will be resolved.
Their values will be inlined in the `values` property.
- *Operations* will be inlined as well.
The `operations` property will contain the list of operations as dotted names.
The `operators` property will contain the full definition of each of those operations supported by that field.
- Indexes that are flagged as *sortable* are listed in a dedicated top-level property `sortable_indexes`.
If an index uses a vocabulary, the vocabulary values are included in the `values` property.
The vocabulary is resolved in the same context where the `/@querystring` endpoint is called (requires `plone.app.querystring >= 2.1.0`).

Available options for the querystring in a Plone site can be queried by interacting with the `/@querystring` endpoint on the portal root:
## Get `querystring` configuration


## Querystring Config

To retrieve all `querystring` options in the portal, call the `/@querystring` endpoint with a `GET` request:
To get the metadata about all query operations available in the portal, call the `/@querystring` endpoint with a `GET` request:

```{eval-rst}
.. http:example:: curl httpie python-requests
:request: ../../../src/plone/restapi/tests/http-examples/querystring_get.req
```

The server will respond with all `querystring` options in the portal:
The server will respond with the metadata:

```{literalinclude} ../../../src/plone/restapi/tests/http-examples/querystring_get.resp
:language: http
Expand Down
1 change: 1 addition & 0 deletions news/1704.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for getting the `/@querystring` endpoint in a specific context. @davisagli
9 changes: 9 additions & 0 deletions src/plone/restapi/services/querystring/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
permission="zope2.View"
name="@querystring"
/>

<plone:service
method="GET"
factory=".get.QuerystringGet"
for="Products.CMFCore.interfaces.IContentish"
permission="zope2.View"
name="@querystring"
/>

<cache:ruleset
for=".get.QuerystringGet"
ruleset="plone.content.dynamic"
Expand Down
2 changes: 1 addition & 1 deletion src/plone/restapi/services/querystring/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class QuerystringGet(Service):
def reply(self):
registry = getUtility(IRegistry)
reader = getMultiAdapter((registry, self.request), IQuerystringRegistryReader)

reader.vocab_context = self.context
result = reader()
result["@id"] = "%s/@querystring" % self.context.absolute_url()
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /plone/front-page/@querystring HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

0 comments on commit 8e2786a

Please sign in to comment.