GSoC 2021 | Week 1–2 — Coding Period @ Hydra Ecosystem

Hasan Faraz Khan
3 min readJun 27, 2021

The coding period for Google Summer of 2021 has started and it’s been two weeks. So here’s my blog about the experience, work done and challenges faced so far.

The first issue I was assigned to was about handling deletion of multiple members from a hydra:Collection and finding a conventional way to do that. This was an improvement I had to do after a previous issue that I previously worked on. Updation of hydra:Resource is allowed in hydrus (our flagship server ) and hydra:Collection is also a subclass of hydra:Resource, however making a POST request to a Collection wasn’t allowed. The reason behind this was that we were still trying to find an effective method to update/delete few hydra:members from a Collection without actually sending the whole collection in the request body which was definitely not the right way to go with as it will increase the server payload. The idea was about creating new endpoints in hydrus which will take both a collection id and it’s member id as parameters. Something like this :

GET: /<api_name>/<collection_name>/<collection_id>/<member_id>
DELETE: /<collection_name>/<collection_id>/delete/<member_id>

This was done in the following :

The next step was allowing the same for deletion of multiple members from the Collection. So, I started looking for better implementation and a found similar implementation for deletion of multiple instances from a Class.

/<api_name>/<class_name>/delete/<ids_list>

At first, I wasn’t sure about this approach, but I stuck to it because something similar to it was already there in our app_factory. I created something similar for Collections as well. The endpoint I created would take name of the collection and a list of object ids as a parameter.

/<api-name>/<resource_name>/<collection-id>/delete/<ids_list>

Here’s the issue and PR for the same :

We had a weekly meeting with the mentors and all active developers in Hydra. In which my mentor Lorenzo M. and Chris Andrew approved the changes but also suggested that we should look for a more conventional way to do this as there was a repetition of keywords like add and delete in the endpoints. Why? Basically, it was there in hydrus so that flask-restful won’t confuse it with other endpoints. Yes, hydrus is built on top of flask. So finally we decided that it would be better to pass the ids separated after a comma as a query parameter instead of using keywords like delete or add .

Also, this would make the code for Resource much cleaner as we won’t have to create separate API views for deletion of single instances or multiple. I had to make this change for all existing routes and request methods, and this was the final result.

/<api-name>/<resource_name>/<collection-id>?instances=<ids_list>

PUT : Class endpoint for creation of multiple objects in a single request.

Request Body :

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

Response ( 201) :

{
"@context":"https://www.w3.org/ns/hydra/core",
"@type": "Status",
"description": "Objects with ID ['id1','id2'] successfully added",
"iri": ["id1","id2"],
"statusCode": 201,
"title": "Objects successfully added"
}

DELETE : Multiple objects from a hydra:Class

URI : /serverapi/Movie?instances=id1,id2,id3

DELETE : Multiple members from a hydra:Collection

URI : /serverapi/MovieCollection/<collection_id>?instances=id1,id2,id3

Response:

{
"@context":"https://www.w3.org/ns/hydra/core",
"@type": "Status",
"description":"Objects with ID ['id1','id2'] successfully deleted",
"statusCode": 200,
"title": "Objects successfully deleted"}
}

The next step after the changes were made was to write test cases for the same and also to improve the test coverage in hydrus. I added some tests for these changes and some more tests to improve the coverage.

PR : https://github.com/HTTP-APIs/hydrus/pull/591

The next checkpoint for upcoming weeks is to implement a foreign key relationship between a hydra:Class and hydra:Collection, so that an object would get deleted automatically from a Collection after it’s deleted from Class table in database. I’ll also have to work on a POC for creating Column types in database. The idea is to look for range of every hydra:supportedProperty and then create Columns with their respective datatypes accordingly.

It’s been a nice experience so far. After suggestion from mentors, I also started reading blogs on how to write more Pythonic code and spent some more time diving deeper into testing frameworks. Also, had good conversations with my colleague Purvanshsingh about RDF, JSON-LD and our future plans. ;-)

--

--