Skip to content

POST/PATCH with multi ids #1010

@Amedeo91

Description

@Amedeo91

Hi all,

for my application I need to provide end-point as follow:
1 carts/<cart_id> --> datasource: carts
2 carts/<cart_id>/products/<product_id> --> datasource: products
3 carts/<cart_id>/products/<product_id>/details/<detail_id> --> datasource: details

My goal is to be able to do all the HTTP method (GET, PATCH, PUT, POST and the embedded resource solver) in using the parameter passed in the URL.

Note: <product_id> and <cart_id> are to be hidden from the client for details and only <cart_id> should be hidden for the products

Below some example:

  • endpoint 1: GET/DELETE search_filter= {id:<cart_id>}
    PUT/PATCH filter_to_update = {id:<cart_id>}
    POST add the query parameter to the request body = {id:<cart_id>}
  • endpoint 2: GET/DELETE search_filter= {cart_id:<cart_id>,id:<product_id>}
    PUT/PATCH filter_to_update = {cart_id:<cart_id>,id:<product_id>}
    POST add the query parameter to the request body = {cart_id:<cart_id>,id:<product_id>}
  • endpoint 3: GET/DELETE search_filter= {cart_id:<cart_id>,product_id:<product_id>, id:<detail_id>}
    PUT/PATCH filter_to_update = {cart_id:<cart_id>,product_id:<product_id>, id:<detail_id>}
    POST add the query parameter to the request body = {cart_id:<cart_id>,product_id:<product_id>, id:<detail_id>}

At the moment I was able to meet my requirement by both adding some hook event (pre_POST, pre_PATCH, pre_PUT) and some customization in the dataLayer.
However, I think it would be nicer to update Eve business logic (especially for the embedded documents).

Moreover, I reckon that the current behavior is kind-of buggy since I am able to POST a new element (i.e. a new product) and I am not able to GET it if the client does not explicitly provide the cartId at the product insert time.

The scenario above it is kind of usefull if the primary-key of our resource is made by more than only one field (therefore, {cart_id:<cart_id>,product_id:<product_id>, id:<detail_id>} should be a primary key for the details resource)

Could you please share with us what do you think about the above scenario?

Regards,
Amedeo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions