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

Changed endpoint format for GET,PUT, DELETE for multiple objects of Class and Collections #590

Merged
merged 8 commits into from Jun 21, 2021
Merged

Conversation

farazkhanfk7
Copy link
Member

@farazkhanfk7 farazkhanfk7 commented Jun 18, 2021

Fixes #587

Checklist

  • My branch is up-to-date with upstream/develop branch.
  • Everything works and tested for Python 3.6.0 and above.

Current behaviour

The current API's endpoint format for operations on collections and deletion/insertion of multiple objects is :

/serverapi/MovieCollection/4f61070a-f647-4a65-9b0a-cbab4bcf0510/delete/3e1462f8-93ad-4a52-a371-a6fd5724c904, 1f6f1df8-788d-430a-8398-2e3302407fc0

Which isn't conventional and there is repetition of keywords like add and delete .

Also, we had lot of code repetition in resource.py ( Items, ItemMember, ItemMembers to operate on single and multiple objects ) when most of it can be done using Item and ItemCollection resource classes with some additional params in request endpoint.

New expected behaviour

Previously, if a user wanted to create multiple objects of a Class, he/she had to pass ids in endpoints as well which can be really time consuming if one wants to PUT multiple objects by making request to a Class endpoint.

PUT (without ids):

/serverapi/Movie

Request Body:

{
  "data": [
    {
      "@type": "Movie",
      "movie_name": "Avengers",
      "movie_director": "Joss Whedon"
    },
    {
      "@type": "Movie",
      "movie_name": "Justice League",
      "movie_director": "Zack Snyder"
    }
  ]
}

PUT ( with ids ):

http://localhost:8080/serverapi/Movie?instances=id1,id2,id3

Response :

{
    "@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
    "@type": "Status",
    "description": "Objects with ID ['98c5a86f-b324-4270-b39b-0af0b7f99d07', '99c5a86f-b324-4270-b39b-0af0b7f99d12'] successfully added",
    "iri": [
        "http://localhost:8080/serverapi/Movie/98c5a86f-b324-4270-b39b-0af0b7f99d07",
        "http://localhost:8080/serverapi/Movie/99c5a86f-b324-4270-b39b-0af0b7f99d12"
    ],
    "statusCode": 201,
    "title": "Objects successfully added"
}

DELETE ( multiple Class objects):

http://localhost:8080/serverapi/Movie?instances=id1,id2,id3

Response :

{
    "@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
    "@type": "Status",
    "description": "Objects with ID ['98c5a86f-b324-4270-b39b-0af0b7f99d07', '99c5a86f-b324-4270-b39b-0af0b7f99d12'] successfully deleted",
    "statusCode": 200,
    "title": "Objects successfully deleted"
}

DELETE ( Multiple members from a Collection)

http://localhost:8080/serverapi/MovieCollection/<collection_id>?instances=id1,id2,id3

Response:

{
    "@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
    "@type": "Status",
    "description": "Objects with ID ['27a3272d-c83d-4b96-8494-2799ac5bd67e', 'ac231414-a1e6-42f2-b6f4-38ec8fbacc4d'] successfully deleted",
    "statusCode": 200,
    "title": "Objects successfully deleted"
}

Change logs

@Mec-iS
Copy link
Contributor

Mec-iS commented Jun 19, 2021

Please use the ?instances= syntax only for operations on multiple objects to accept lists.
there is no reason to change the semantics for single-instance operations, stick to what has been done on the non-collections endpoints.

@Mec-iS Mec-iS self-requested a review June 19, 2021 11:38
Mec-iS
Mec-iS previously requested changes Jun 19, 2021
Copy link
Contributor

@Mec-iS Mec-iS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment #590 (comment)

@farazkhanfk7
Copy link
Member Author

Changed query parameter to ?instances= for all endpoints.

hydrus/resources.py Outdated Show resolved Hide resolved
@Mec-iS Mec-iS dismissed their stale review June 21, 2021 14:26

corrections made

@farazkhanfk7 farazkhanfk7 requested a review from Mec-iS June 21, 2021 16:48
@Mec-iS Mec-iS merged commit 3a9252e into HTTP-APIs:develop Jun 21, 2021
@farazkhanfk7 farazkhanfk7 added this to Finished in GSOC-2021-month-1 Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Change GET PUT POST DELETE requests format for collections
2 participants