diff --git a/docs/.docz/app/db.json b/docs/.docz/app/db.json index 26d643a..d1a2d20 100644 --- a/docs/.docz/app/db.json +++ b/docs/.docz/app/db.json @@ -8,7 +8,7 @@ { "name": "Tutorial", "menu": [ - "First Tutorial" + "Making CRUD operations with Hydrus" ] }, { @@ -94,17 +94,17 @@ } }, { - "key": "src/content/FAQs/first.md", + "key": "src/content/conceptual-guides/first.md", "value": { - "name": "Some Questions", - "menu": "FAQ", - "id": "4a48a1d15c64d789680a44008caf5791", - "filepath": "src/content/FAQs/first.md", - "fullpath": "/Users/priyanshunayan/Developer/gsoc/docs/docs/src/content/FAQs/first.md", - "link": "https://github.com/http-apis/docs/edit/master/docs/src/content/FAQs/first.md", + "name": "Conceptual Guide 1", + "menu": "Conceptual Guides", + "id": "29afc96bd22c4e047c5240f3d29ab70c", + "filepath": "src/content/conceptual-guides/first.md", + "fullpath": "/Users/priyanshunayan/Developer/gsoc/docs/docs/src/content/conceptual-guides/first.md", + "link": "https://github.com/http-apis/docs/edit/master/docs/src/content/conceptual-guides/first.md", "hidden": false, - "slug": "src-content-fa-qs-first", - "route": "/src-content-fa-qs-first", + "slug": "src-content-conceptual-guides-first", + "route": "/src-content-conceptual-guides-first", "headings": [ { "slug": "some-random-content", @@ -115,17 +115,17 @@ } }, { - "key": "src/content/conceptual-guides/first.md", + "key": "src/content/FAQs/first.md", "value": { - "name": "Conceptual Guide 1", - "menu": "Conceptual Guides", - "id": "29afc96bd22c4e047c5240f3d29ab70c", - "filepath": "src/content/conceptual-guides/first.md", - "fullpath": "/Users/priyanshunayan/Developer/gsoc/docs/docs/src/content/conceptual-guides/first.md", - "link": "https://github.com/http-apis/docs/edit/master/docs/src/content/conceptual-guides/first.md", + "name": "Some Questions", + "menu": "FAQ", + "id": "4a48a1d15c64d789680a44008caf5791", + "filepath": "src/content/FAQs/first.md", + "fullpath": "/Users/priyanshunayan/Developer/gsoc/docs/docs/src/content/FAQs/first.md", + "link": "https://github.com/http-apis/docs/edit/master/docs/src/content/FAQs/first.md", "hidden": false, - "slug": "src-content-conceptual-guides-first", - "route": "/src-content-conceptual-guides-first", + "slug": "src-content-fa-qs-first", + "route": "/src-content-fa-qs-first", "headings": [ { "slug": "some-random-content", @@ -178,48 +178,66 @@ } }, { - "key": "src/content/tutorial/first.md", + "key": "src/content/tutorial/making-crud-operations-using-hydrus.md", "value": { - "name": "First Tutorial", + "name": "Making CRUD operations with Hydrus", "menu": "Tutorial", - "id": "7e38d0e1827b6eb2d95595ac83502ae1", - "filepath": "src/content/tutorial/first.md", - "fullpath": "/Users/priyanshunayan/Developer/gsoc/docs/docs/src/content/tutorial/first.md", - "link": "https://github.com/http-apis/docs/edit/master/docs/src/content/tutorial/first.md", + "id": "baa4e03d3fa819440dedcbc876605c3c", + "filepath": "src/content/tutorial/making-crud-operations-using-hydrus.md", + "fullpath": "/Users/priyanshunayan/Developer/gsoc/docs/docs/src/content/tutorial/making-crud-operations-using-hydrus.md", + "link": "https://github.com/http-apis/docs/edit/master/docs/src/content/tutorial/making-crud-operations-using-hydrus.md", "hidden": false, - "slug": "src-content-tutorial-first", - "route": "/src-content-tutorial-first", + "slug": "src-content-tutorial-making-crud-operations-using-hydrus", + "route": "/src-content-tutorial-making-crud-operations-using-hydrus", "headings": [ { - "slug": "first-tutorial", + "slug": "making-crud-operations-using-hydrus", "depth": 1, - "value": "First Tutorial" + "value": "Making CRUD Operations using Hydrus" + }, + { + "slug": "adding-a-resource", + "depth": 2, + "value": "Adding a resource" + }, + { + "slug": "modifying-a-resource", + "depth": 2, + "value": "Modifying a resource" }, { - "slug": "how-to-say-hello-in-python", + "slug": "getting-a-resource", "depth": 2, - "value": "How to say hello in Python?" + "value": "Getting a resource" }, { - "slug": "how-to-say-hello-in-python-again", + "slug": "creating-a-collection", "depth": 2, - "value": "How to say hello in Python Again?" + "value": "Creating a Collection" + }, + { + "slug": "getting-a-collection", + "depth": 2, + "value": "Getting a Collection" + }, + { + "slug": "updating-a-collection", + "depth": 2, + "value": "Updating a Collection" + }, + { + "slug": "deleting-class-instances-and-collection-instances", + "depth": 2, + "value": "Deleting Class Instances and Collection Instances" + }, + { + "slug": "in-this-document-you-learned-about", + "depth": 2, + "value": "In this document you learned about:" } ] } } ], - "props": [ - { - "key": "src/components/roadmap.js", - "value": [ - { - "description": "", - "displayName": "Roadmap", - "methods": [], - "actualName": "Roadmap" - } - ] - } - ] + "props": [] } diff --git a/docs/doczrc.js b/docs/doczrc.js index f0b27e4..48d5a4d 100644 --- a/docs/doczrc.js +++ b/docs/doczrc.js @@ -3,7 +3,7 @@ export default { menu:[ "Welcome to Hydra Ecosystem Docs", "Quickstart", - {name: 'Tutorial', menu:['First Tutorial']}, + {name: 'Tutorial', menu:['Making CRUD operations with Hydrus']}, {name: 'How To Guides', menu: ['First How to Guide']}, {name: 'Conceptual Guides', menu: ['Conceptual Guide 1']}, {name: 'Modules', menu: ['Hydra in Depth']}, diff --git a/docs/src/content/tutorial/first.md b/docs/src/content/tutorial/first.md deleted file mode 100644 index 8a1d209..0000000 --- a/docs/src/content/tutorial/first.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -name: First Tutorial -menu: Tutorial ---- - -# First Tutorial - -## How to say hello in Python? - -```python - import __hello__ - def hello(): - print("Hello there, again") - -``` - -## How to say hello in Python Again? - -```python - import __hello__ - def hello(): - print("Hello there, again") - -``` diff --git a/docs/src/content/tutorial/making-crud-operations-using-hydrus.md b/docs/src/content/tutorial/making-crud-operations-using-hydrus.md new file mode 100644 index 0000000..ce3ce5f --- /dev/null +++ b/docs/src/content/tutorial/making-crud-operations-using-hydrus.md @@ -0,0 +1,109 @@ +--- +name: Making CRUD operations with Hydrus +menu: Tutorial +--- + +# Making CRUD Operations using Hydrus + +> You should have hydrus up and running to follow along with this tutorial. To start hydrus please visit this tutorial. You should also have [Postman](https://www.postman.com/) or a similar tool installed. + +To check if `hydrus` is up and running, open Postman and make a `GET` request to `http://localhost:8080/api`. You should see the following response on Postman: + +![Postman Screenshot of GET request](../../../static/images/image5.png) + +Most of the time we are dealing with the resources. Common operations include creating resources, updating resource, getting the resource, or deleting the resource. `hydrus` uses the HTTP verbs to carry out these operations. It uses GET to get the resources, PUT to add a resource, POST to modify a resource, and DELETE to delete a resource. + +In Hydra dereferenceable resources are called classes. In Hydra parlance resources need not be dereferenceable. A `hydra:Collection` is a set of somehow related resources. It can contain members of different types. The entry point lists all the resources defined in APIDoc such as Movie and Movie Collection. The Movie or Movie Collection resources supports only the operations that are described by `hydra:supportedOperation` in the APIDoc. + +## Adding a resource + +Let’s start by adding a movie. To add a movie, in Postman make a PUT request to `http://localhost:8080/api/Movie` with the following request body in JSON: + +```json +{ + "@type": "Movie", + "movie_name": "Godfather", + "movie_director": "Francis Ford Coppola" +} +``` + +![Postman Screenshot of PUT request](../../../static/images/image2.png) + +The object was successfully added. The response returns with an object ID which can be used to dereference this Movie. The object Id or the id of the instance of this Movie class is the alphanumeric sequence in the `description` field of the object. To see the added movie make a GET request to `http://localhost:8080/api/Movie/`. + +## Modifying a resource + +Let’s change the director’s name from Francis Ford Coppola to F.F. Coppola. To modify a request make a POST request to `http://localhost:8080/api/Movie/`. Object Id being the ID of the resource to be modified, with the request body as + +```json +{ + "movie_name": "Godfather", + "movie_director": "F.F Coppola", + "@type": "Movie" +} +``` + +This will modify the resource with the updated value of `movie_director`. + +## Getting a resource + +To check if the resource was updated make a GET request at the same URL and you can see the updated response. + +## Creating a Collection + +Now, add this Movie to a collection. To create a collection and add movies to it make a PUT request to `http://localhost:8080/api/MovieCollection` with the request body in JSON containing the IDs of movies to add, and their type: + +```json +{ + "@type": "MovieCollection", + "members": [ + { + "@id": "api/Movie/8abc6bdb-b572-40ab-a082-a808aec453f7", + "@type": "Movie" + } + ] +} +``` + +![Postman Screenshot of PUT request](../../../static/images/image1.png) + +The response contains the ID of the new collection. +Note that we can add only already created Class instances as members. + +## Getting a Collection + +To GET the new created collection, make a GET request to `http://localhost:8080/api/MovieCollection/`. Collection ID the alpha-numeric sequence in the description field of the response. + +![Postman Screenshot of GET request](../../../static/images/image4.png) + +## Updating a Collection + +Updating a collection is similar to creating a collection. Only difference is that this operation takes place at `/api/collection-name/` url. It takes in the members array to update the list of resources. For eg: to replace the current movie in the collection with something else we can make a POST request to `http://localhost:8080/api/MovieCollection/` with the updated members: + +```json +{ + "@type": "MovieCollection", + "members": [ + { + "@type": "Movie", + "@id": "/api/Movie/sdjhf-sdgjkhf-ksdjfgh" + } + ] +} +``` + +Note that these members should exist before they are added to the collection. + +## Deleting Class Instances and Collection Instances + +To delete a resource make a DELETE operation on the `http://localhost:8080/api/Movie/`. Similarly to delete a collection, make DELETE operation to `http://localhost:8080/api/MovieCollection/`. + +Note that we were making GET, PUT, POST, DELETE operation because we had specified them on the APIDoc created in Tutorial 2. It might not always be the case. Also, we did not pass any additional authorization headers because we had disabled the authentication. Many a times we want protected routes. See the How-to-Guides on How to use Authentication. + +## In this document you learned about: + +- Hydra classes and collection +- CRUD operation on Hydra classes +- CRUD operation on Hydra collection + +Now, move on next tutorial, Using Agent to make CRUD operations ➡️ diff --git a/docs/src/styles/global.css b/docs/src/styles/global.css index 691a5c9..c32f0d7 100644 --- a/docs/src/styles/global.css +++ b/docs/src/styles/global.css @@ -1,5 +1,5 @@ @import url("https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap"); -* { +html { font-family: "Roboto", sans-serif !important; } diff --git a/docs/static/images/image1.png b/docs/static/images/image1.png new file mode 100644 index 0000000..d1f239a Binary files /dev/null and b/docs/static/images/image1.png differ diff --git a/docs/static/images/image2.png b/docs/static/images/image2.png new file mode 100644 index 0000000..d50d88d Binary files /dev/null and b/docs/static/images/image2.png differ diff --git a/docs/static/images/image3.png b/docs/static/images/image3.png new file mode 100644 index 0000000..35e6710 Binary files /dev/null and b/docs/static/images/image3.png differ diff --git a/docs/static/images/image4.png b/docs/static/images/image4.png new file mode 100644 index 0000000..f05b168 Binary files /dev/null and b/docs/static/images/image4.png differ diff --git a/docs/static/images/image5.png b/docs/static/images/image5.png new file mode 100644 index 0000000..c9fca75 Binary files /dev/null and b/docs/static/images/image5.png differ