Skip to content

Commit 912f0a9

Browse files
authored
Merge pull request #3 from HTTP-APIs/workflow_tutorial
Workflow tutorial
2 parents 4f09ac4 + c3a7bf4 commit 912f0a9

File tree

4 files changed

+107
-25
lines changed

4 files changed

+107
-25
lines changed

docs/doczrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default {
33
menu:[
44
"Welcome to Hydra Ecosystem Docs",
55
"Quickstart",
6-
{name: 'Tutorial', menu:['First Tutorial']},
6+
{name: 'Tutorial', menu:['Workflow']},
77
{name: 'How To Guides', menu: ['First How to Guide']},
88
{name: 'Conceptual Guides', menu: ['Conceptual Guide 1']},
99
{name: 'Usage', menu: ['CLI Usage of hydrus']},

docs/src/content/tutorial/first.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

docs/src/content/tutorial/workflow.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
name: Workflow
3+
menu: Tutorial
4+
---
5+
6+
# General Workflow
7+
8+
> This document assumes no prerequisites. If you are familiar with Hydra, Linked Data (W3C), and Web API jump [here](#main).
9+
10+
## Familiarizing with Hydra
11+
12+
The [specification](http://www.hydra-cg.com/spec/latest/core/) defines Hydra as:
13+
14+
> a lightweight vocabulary to create hypermedia-driven Web APIs. By specifying a number of concepts commonly used in Web APIs it enables the creation of generic API clients.
15+
16+
Hydra enables a server to advertise valid state transitions in a machine-processable way. The information can be changed or modified at a runtime which the agents can understand and adapt to it. In Hydra Ecosystem the smart client is called a 'agent'.
17+
18+
The smart clients look for the API Documentation(APIDoc) in the Link header. The APIDoc is a completely machine-processable document. It is the foundation of the description of the Web API. It describes the API by giving it a title, a short description, and documenting its main entry point. The supported operations, status codes that might be returned can also be documented. Hydra vocabulary formalizes these concepts. To know more in-depth, consider reading [official specification.](http://www.hydra-cg.com/spec/latest/core/#documenting-a-web-api)
19+
20+
## Linked Data
21+
22+
[Tim Berners Lee defines](https://www.w3.org/DesignIssues/LinkedData.html) linked data as:
23+
24+
> The Semantic Web isn't just about putting data on the web. It is about making links so that a person or machine can explore the web of data. With linked data, when you have some of it, you can find other, related, data.
25+
26+
There are three rules that the Linked Data (W3C) should follow:
27+
28+
1. Use URI for names of things
29+
2. Use HTTP URIs so that people can look up those names.
30+
3. When someone looks up a URI, provide useful information, using the standards.
31+
4. Include links to other URIs. so that they can discover more things.
32+
33+
With Linked Data (W3C), it becomes easy to integrate different datasets to achieve conceived goals. One of the common examples of Linked data dataset is [DBPedia](https://wiki.dbpedia.org/)(the dataset of Wikipedia in Linked Data(W3C) format).
34+
35+
## JSON-LD
36+
37+
[JSON-LD](https://json-ld.org/) is a JSON based format to serialize Linked Data (W3C). It annotates the elements of the response and structures the data which helps to disambiguate different data and helps machines better understand the data.
38+
For example, any human can comprehend that the following response contains data about the name Hydra Ecosystem and contains the URL of the home page. But machines cannot make any sense from the following data.
39+
40+
```json
41+
{
42+
"name": "Hydra Ecosystem",
43+
"homepage": "https://hydraecosystem.org/"
44+
}
45+
```
46+
47+
To resolve this, one can use unambiguous identifiers for the name and URL and specify that if the value is an IRI or a string literal. JSON-LD can be used to achieve this by using a popular schema.org vocabulary: <!-- Insert link -->
48+
49+
```json
50+
{
51+
"http://schema.org/name": "Hydra Ecosystem",
52+
"http://schema.org/url": {
53+
"@id": "https://hydraecosystem.org/"
54+
↑ The '@id' keyword means 'This value is an identifier that is an IRI
55+
}
56+
}
57+
```
58+
59+
## Web APIs
60+
61+
A Web API is an application programming interface for either a web server or a web browser. One can get the data without bothering about the implementation details. For example, to get the weather information of a place, one need not to bother about how the weather is measured. A request to the URL of the API returns with the weather information.
62+
63+
<div id="main">
64+
After going through this document, you will understand the general workflow followed to create and use APIs using the tools of the Hydra Ecosystem.
65+
</div>
66+
67+
To design web APIs using the tools of this ecosystem, follow three simple steps.
68+
69+
1. Define the API in JSON-LD format as API Documentation
70+
2. Pass this API Documentation to the `hydrus` server
71+
3. Use Smart clients(`hydra-python-agent`) to consume APIs served by the `hydrus`.
72+
73+
See the following image to get an idea of how different components of the Hydra Ecosystem interact with each other:
74+
75+
![Workflow Diagram](../../../static/images/workflow.png)
76+
77+
## 1. Defining the API Documentation
78+
79+
Define the API documentation(APIDoc) by using the tool `hydra-python-core`. `hydra-python-core` provides convenient interfaces for describing the API in Hydra parlance in Python programming language, i.e the supported classes, supported operations along with the other properties defined by the Hydra specification.
80+
81+
`hydra-python-core` also accepts the predefined APIDoc in JSON-LD format and in OpenAPI format. To convert the APIDoc from OpenAPI format to JSON-LD format use [`hydra-openapi-parser`](https://github.com/HTTP-APIs/hydra-openapi-parser).
82+
83+
`doc_maker` module of `hydra-python-core` changes the existing APIDoc in JSON-LD to Python classes using the `doc_writer` module, which the tools like `hydra-python-agent` and `hydrus` can understand.
84+
85+
## 2. Passing the API documentation to `hydrus`
86+
87+
`hydrus` accepts the APIDoc as a parameter and spins up a server, and exposes routes for every Hydra Class and Collection with the allowed operations as defined in the APIDoc. One can configure the authentication mechanism and the database.
88+
89+
`hydrus` can be used as a Command Line Interface(CLI) and as a python package.
90+
91+
`hydrus` can be connected with agents using web sockets as well as without it. `hydrus` uses web sockets to sync data between multiple clients connected to it by using message-passing protocol.
92+
93+
## 3. Using smart clients to consume APIs
94+
95+
Once the server is up and running, any smart agent like `hydra-python-agent` can consume the APIs. `hydra-python-agent` can be used in a REPL or as a python package to interact with `hydrus` or any http powered web server.
96+
97+
The [GUI](https://github.com/HTTP-APIs/hydra-python-agent-gui) is built on the top of the `hydra-python-agent` to interact with the server. It is built up of two components - graph and a form. Graph represents the APIDoc in graphical format. One can use the forms to create different type of requests to the `hydrus`.
98+
![GUI](https://miro.medium.com/max/4800/1*hFFdEHw-yLhmMuezUaC3Bw.png)
99+
100+
### To Summarise, from this document you:
101+
102+
- Learnt about Hydra, JSON-LD, Linked Data (W3C), and web APIs.
103+
- Learnt about the general workflow to follow to create and use web APIs.
104+
- Learnt about the different tools of the Hydra ecosystem
105+
106+
Now, move on to the next section [Creating a sample APIDoc ➡️](https://google.com)

docs/static/images/workflow.png

65.2 KB
Loading

0 commit comments

Comments
 (0)