Coder Social home page Coder Social logo

Comments (8)

tisto avatar tisto commented on July 1, 2024

@lukasgraf thanks for the writeup! I tried to wrap my head around this issue as well and haven't reached a final conclusion yet.

You can ignore searching.rst. This was a very early draft before we even looked at existing solutions. I will try to find some time to do some more research. Though, this seems to be a topic that most API architects seem to avoid talking about. ;)

Just a remark regarding POST vs. GET. It seems that some people argue that you actually create a search with a query and therefore a POST request can also be correct in REST terms. Though, you are of course correct with the other disadvantages (caching, no URL, etc.).

from plone.restapi.

bloodbare avatar bloodbare commented on July 1, 2024

Great job @lukasgraf !

I love your ideas, in some projects we are using JWT (jwt.io) to have the search query on a parameter as they can be complex. If we wanna support complex queries , the parameters get complex and jwt allows to define a JSON format.

I would support only GET verb.

It may be an option to have to endpoints ? one for text search and one for complex search ?

from plone.restapi.

lukasgraf avatar lukasgraf commented on July 1, 2024

@tisto

Just a remark regarding POST vs. GET. It seems that some people argue that you actually create a search with a query and therefore a POST request can also be correct in REST terms. Though, you are of course correct with the other disadvantages (caching, no URL, etc.).

Yes, I've also seen POST being used. I created a separate issue #46 for discussing a potential concept to maybe address some race conditions with batching - that would require a POST anyway.

@bloodbare

If we wanna support complex queries , the parameters get complex and jwt allows to define a JSON format.

Yes, for any non-trivial query I don't really see anything besides JSON as an option any more. We really don't want to write our own query DSL.

I would support only GET verb.

We (4tw) also have a strong tendency towards that, if we can make it work.

I'd argue that then means that 3) (GET + JSON in query string) emerges as a promising option.

It may be an option to have to endpoints ? one for text search and one for complex search ?

Yes, we also considered that. For now I'd like to focus on an implementation that can gracefully handle complex queries, because that's the hard case, but I could very well see a limited simple_search endpoint with a simplified syntax and reduced functionality.

from plone.restapi.

jone avatar jone commented on July 1, 2024

I'd love to have a simple JSON-payload rather than having to build a compliacated GET-querystring.
Because GET + payload is a problem I'm therefore in favor of using payloads with POST-requests (nr. 4.)

from plone.restapi.

lukasgraf avatar lukasgraf commented on July 1, 2024

For 3) it would be about as complicated as this 😜

query_json = quote_plus(json.dumps(query))
requests.get(url, params={'q': json_query})

Or with curl:

 curl -G -H 'Accept: application/json' $URL --data-urlencode 'q={"SearchableText": "foobar"}'

Or with httpie:

http -j GET $URL q=='{"SearchableText": "foobar"}'

Maybe offering both is the way to go? As long as the serialization format is JSON for both, implementation and documentation overhead should be minimal.

from plone.restapi.

jone avatar jone commented on July 1, 2024

That's for me ok as well. I think we should just implement a first version; it can be extended later..

from plone.restapi.

lukasgraf avatar lukasgraf commented on July 1, 2024

Updated:
The use of JSON only allows to retain some typing information, but not all (datetime isn't JSON serializable).

This significantly diminishes the advantage of the use of JSON as the query serialization format, because we still need to have a mechanism in place to reconstruct typing information based on knowledge about the index that's being queried.

Under these circumstances I really don't see a point in also offering POST anymore. While on the implementation side it's trivial to also support POST, it still needs to be tested and documented. Also, offering two ways to do the same thing goes against the Zen of Python There should be one-- and preferably only one --obvious way to do it., and might confuse our users.

For this reason, I think GET with query string and optional Zope type hints is the way to go. I'll update my search PR (#48) accordingly in the next few days and propose a GET only implementation.

from plone.restapi.

lukasgraf avatar lukasgraf commented on July 1, 2024

A first version implementing GET with query string has been merged with #48

from plone.restapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.