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

Tutorials for making crud operations using Postman #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 64 additions & 46 deletions docs/.docz/app/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"name": "Tutorial",
"menu": [
"First Tutorial"
"Making CRUD operations with Hydrus"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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": []
}
2 changes: 1 addition & 1 deletion docs/doczrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']},
Expand Down
24 changes: 0 additions & 24 deletions docs/src/content/tutorial/first.md

This file was deleted.

109 changes: 109 additions & 0 deletions docs/src/content/tutorial/making-crud-operations-using-hydrus.md
Original file line number Diff line number Diff line change
@@ -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/<object-id>`.

## 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>`. 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>`. 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/<collection-id>` 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/<collection-id>` 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/<resource-id>`. Similarly to delete a collection, make DELETE operation to `http://localhost:8080/api/MovieCollection/<collection-id>`.

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 ➡️
2 changes: 1 addition & 1 deletion docs/src/styles/global.css
Original file line number Diff line number Diff line change
@@ -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;
}
Binary file added docs/static/images/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/static/images/image5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.