Adding docs

This commit is contained in:
Luca Frosini 2022-09-13 19:00:30 +02:00
parent 0aa7135e90
commit 66810e67a4
1 changed files with 110 additions and 2 deletions

View File

@ -6,6 +6,7 @@
Welcome to gCat documentation!
=================================================
gCat is a RESTful application which exposes operations ...
See the available REST-API on `its API docs <../api-docs/index.html>`_.
@ -25,11 +26,118 @@ Specifically, the implementation fully adopts `OIDC (OpenID Connect) <https://op
Obtain your Bearer token here: https://dev.d4science.org/how-to-access-resources
Service
==================
The methods of the Web Service can be called by writing your own REST client application or by using already existing REST client plugins.
Content Type
------------------
Any request must contain the indication of the interested content type.
For any operation returning a result, the client must specify the **Accept** HTTP Header.
.. code-block:: rest
Accept: application/json
For any operation sending content to the service, it is necessary to specify the **Content-Type** HTTP Header.
.. code-block:: rest
Content-Type: application/json
Actually, the service accepts and returns only JSON objects.
Except for a `Profile Collection <../api-docs/resource\_Profile.html>`_ which must be manipulated in in XML.
HTTP Statuses
------------------
Any successful operation returns *200 OK* status code except for create operation which return *201 Created* or for the operations which do not provide any content and returns *204 No Content*.
The most common error status a client can obtain are:
* **400 Bad Request** used to indicate a clients error `<https://tools.ietf.org/html/rfc7231#section-6.5.1>`_;
* **401 Unauthorized** used to indicate that the client does not provided the gcube-token HTTP Header or the clinet has not enough right to perform such request `<https://tools.ietf.org/html/rfc7235#section-3.1>`_;
* **404 Not Found** used to indicate that the requested instance does not exists `<https://tools.ietf.org/html/rfc7231#section-6.5.4>`_;
* **405 Method Not Allowed** the used HTTP method is not supported for the requested URL `<https://tools.ietf.org/html/rfc7231#section-6.5.5>`_.
The response contains the *Allow* HTTP Header indicating the supported HTTP method for such URL `<https://tools.ietf.org/html/rfc7231#section-7.4.1>`_;
* **409 Conflict** the request could not be completed due to a conflict with the current state of the target resource (e.g. the name of the resource already exists) `<https://tools.ietf.org/html/rfc7231#section-6.5.8>`_;
* **500 Internal Server Error** indicate a server failure `<https://tools.ietf.org/html/rfc7231#section-6.6.1>`_.
A complete list of HTTP Status can be found here:
`<https://httpstatuses.com/>`_
I you get a *500 Internal Server Error* please report it in the gCube ticketing system.
Please use this checklist before reporting an error:
* replicate the request
* the failure could be temporal due to network error, server issue so please retry the request after a certain amount of time
* indicate how to replicate the error
* indicate the time when the error occurred (this simplify the identification of the issue)
=== HTTP Methods ===
To be RESTful compliant gCat uses standard HTTP Methods to perform a listing of collections and CRUD (Create Read Update Delete) operations on instances.
{| class="wikitable"
! Operation || HTTP Method || URL || Success HTTP Status || Safe || Idempotent
|-
| Supported<br />HTTP Methods || OPTIONS || /{COLLECTION} || 204 No Content<br />(Supported HTTP Methods in ''Allow'' HTTP Header) || Y || Y
|-
| List || GET || /{COLLECTION} || 200 OK || Y || Y
|-
| Count || GET || /{COLLECTION}?count=true || 200 OK || Y || Y
|-
| Exists || HEAD || /{COLLECTION} || 204 No Content || Y || Y
|-
| Create || POST || /{COLLECTION} || 201 Created || N || N
|-
| Supported<br />HTTP Methods || OPTIONS || /{COLLECTION}/{INSTANCE_ID} || 204 No Content<br />(Supported HTTP Methods in ''Allow'' HTTP Header) || Y || Y
|-
| Exist || HEAD || /{COLLECTION}/{INSTANCE_ID} || 204 No Content || Y || Y
|-
| Read || GET || /{COLLECTION}/{INSTANCE_ID} || 200 OK || Y || Y
|-
| Update || PUT || /{COLLECTION}/{INSTANCE_ID} || 200 OK || N || Y
|-
| Patch || PATCH || /{COLLECTION}/{INSTANCE_ID} || 200 OK || N || Y
|-
| <span id="delete">Delete</span> || DELETE || /{COLLECTION}/{INSTANCE_ID} || 204 No Content || N || N [[#non_safe_delete| ‡]]
|-
| Purge || PURGE || /{COLLECTION}/{INSTANCE_ID} || 204 No Content || N || N[[#non_safe_delete| ‡]]
|-
| Purge || DELETE || /{COLLECTION}/{INSTANCE_ID}?purge=true || 204 No Content || N || N[[#non_safe_delete| ‡]]
|}
About URL:
* {COLLECTION} is the plural name of the entity type;
* {INSTANCE_ID} is an identification which enables to univocally identify the instance in the collection.
About Safety and Idempotency properties:
* A method is *Safe* if it does not produce any side effects. "''This does not prevent an implementation from including behaviour that is potentially harmful, that is not entirely read-only, or that causes side effects while invoking a safe method''" [https://tools.ietf.org/html/rfc7231#section-4.2.1 https://tools.ietf.org/html/rfc7231#section-4.2.1];
* A method is *Idempotent* if the same operation repeated multiple times has the same side effect than using it one time. "''repeating the request will have the same intended effect, even if the original request succeeded, though the response might differ''" [https://tools.ietf.org/html/rfc7231#section-4.2.2 https://tools.ietf.org/html/rfc7231#section-4.2.2].
[[#delete|‡]] DELETE has been defined as idempotent. <span id="non_safe_delete">Allamaraju</span><ref>Allamaraju S. RESTful Web Services Cookbook: Solutions for Improving Scalability and Simplicity . OReilly. first ed. 2010</ref> argues that DELETE idempotency should be accomplished client-side. The server should inform the client if a delete succeeded because the resource was really deleted or it was not found i.e., *404 Not Found* error is suggested instead of *204 No Content*. The latter situation should be treated as idempotent by the client. For this reason, gCat does not provide server-side idempotency for DELETE and PURGE operations.
You can find more information about HTTP Methods at [https://restfulapi.net/http-methods/ https://restfulapi.net/http-methods/]
Uncommon HTTP Methods:
* PATCH method allows to perform a differential update (i.e. an update which provide only the differences and not the whole new representation) [];
* PURGE method is not a standard but is a widely used in service which requires this action (e.g. [https://varnish-cache.org/docs/3.0/tutorial/purging.html Varnish], [https://wiki.squid-cache.org/SquidFaq/OperatingSquid#How_can_I_purge_an_object_from_my_cache.3F Squid]). gCat provide support for this method but to support a wider range of clients it also provides the Purge action via DELETE with the additional get parameter <pre>purge=true</pre>
Java Client
==================
The methods of the Web Service can be called by writing your own REST client application or by using already existing REST client plugins. We provide the following Java Client out-of-the-box.
We provide the following Java Client out-of-the-box.
.. TIP::
If you're coding in Java it is recommended that you use this Java Client.