resgateio / resgate

A Realtime API Gateway used with NATS to build REST, real time, and RPC APIs, where all your clients are synchronized seamlessly.
https://resgate.io
MIT License
685 stars 67 forks source link

Allow query on non-query get request #110

Closed jirenius closed 4 years ago

jirenius commented 4 years ago

Issue

The RES protocol currently doesn't allow responding with a query resource on a non-query get request. In the RES Service Protocol - Get request, it states in the Result section:

query
MUST be omitted if the request had no query parameter.

This restriction should be removed as it may cause unnecessary complexity for service development of query resource that uses default values for omitted query parameters.

Use case

Assume we have a collection of a million items, but the service wish to only expose the collection as a query resource where a from and limit parameter may be provided to specify the span.

To simplify the request, omitting any of the two parameters will have the service fall back to the default values (eg. from=0&limit=50).

If both parameters were omitted, the query would be empty, and due to the restriction it would no longer accept a normalized query in the response. This would currently force the developers to either:

1) Add specific non-query handling on the service for the default params usecase. 2) Add a dummy property to the query (eg. ignore=this) on the request

This scenario would be solved if the restriction was lifted.

Example request

Request body for get.example.list:

{ }

Response:

{
    "result": {
        "collection": [{ "rid": "example.item.1" }, ... , { "rid": "example.item.50" }],
        "query": "from=0&limit=50"
    }
}

Compatibility

Removing the restriction would:

jirenius commented 4 years ago

Resolved in PR #117