haveapi 0.26.3 → 0.26.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/create-client.md +107 -0
- data/doc/json-schema.html +1182 -0
- data/doc/protocol.md +535 -0
- data/doc/protocol.png +0 -0
- data/haveapi.gemspec +1 -1
- data/lib/haveapi/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2aaba661c1079ed4477b407baa76f18076b11547db5fde580dc0fefda6af575e
|
|
4
|
+
data.tar.gz: cef021ca91b4a94357d3dd1d14896cc1cf1058ecb2c8f6eedef8e3ad8cbf32c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 739e1ec05795c57ab4e54cf28b563a711927a23692a1c5070e0ea97adb66fbdde45c88a38f75ed221c88231ae0d3eb7a47f82e425f4712d5dfba56a3a020faae
|
|
7
|
+
data.tar.gz: f7fbf1852b104206dc050c6456609e36b47a8835a9cfe230d24413739978069259c37bda866119536c23abf2a74e7ee094eab48c8d538981f45e32581a35e494
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Client definition
|
|
2
|
+
It is necessary to differentiate between clients for HaveAPI based APIs
|
|
3
|
+
and clients to work with your API instance. This document describes
|
|
4
|
+
the former. If you only want to use your API, you should check a list
|
|
5
|
+
of available clients and pick the one in the right language. Only when
|
|
6
|
+
there isn't a client already available in the language you want, then
|
|
7
|
+
continue reading.
|
|
8
|
+
|
|
9
|
+
# Design rules
|
|
10
|
+
The client must completely depend on the API description:
|
|
11
|
+
|
|
12
|
+
- it has no assumptions and API-specific code,
|
|
13
|
+
- it does not know any resources, actions and parameters,
|
|
14
|
+
- everything the client knows must be found out from the API description.
|
|
15
|
+
|
|
16
|
+
All clients should use a similar paradigm, so that it is possible to use
|
|
17
|
+
clients in different languages in the same way, as far as the language syntax
|
|
18
|
+
allows. Clients bundled with HaveAPI may serve as a model. A client should
|
|
19
|
+
use all the advantages and coding styles of the language it is written
|
|
20
|
+
in (e.g. use objects in object oriented languages).
|
|
21
|
+
|
|
22
|
+
A model paradigm (in no particular language):
|
|
23
|
+
|
|
24
|
+
// Create client instance
|
|
25
|
+
api = new HaveAPI.Client("https://your.api.tld")
|
|
26
|
+
|
|
27
|
+
// Authenticate
|
|
28
|
+
api.authenticate("basic", {"user": "yourname", "password": "yourpassword"})
|
|
29
|
+
|
|
30
|
+
// Access resources and actions
|
|
31
|
+
api.<resource>.<action>( { <parameters> } )
|
|
32
|
+
api.user.new({"name": "Very Name", "password": "donottellanyone"})
|
|
33
|
+
api.user.list()
|
|
34
|
+
api.nested.resource.deep.list()
|
|
35
|
+
|
|
36
|
+
// Pass IDs to resources
|
|
37
|
+
api.nested(1).resource(2).deep.list()
|
|
38
|
+
|
|
39
|
+
// Object-like access
|
|
40
|
+
user = api.user.show(1)
|
|
41
|
+
user.id
|
|
42
|
+
user.name
|
|
43
|
+
user.destroy()
|
|
44
|
+
|
|
45
|
+
// Logout
|
|
46
|
+
api.logout()
|
|
47
|
+
|
|
48
|
+
# Necessary features to implement
|
|
49
|
+
A client should implement all of the listed features in order to be useful.
|
|
50
|
+
|
|
51
|
+
## Resource tree
|
|
52
|
+
The client gives access to all listed resources and their actions.
|
|
53
|
+
|
|
54
|
+
In scripting languages, resources and actions are usually defined as dynamic
|
|
55
|
+
properties/objects/methods, depending on the language.
|
|
56
|
+
|
|
57
|
+
## Input/output parameters
|
|
58
|
+
Allow sending input parameters and accessing the response.
|
|
59
|
+
|
|
60
|
+
## Input/output formats
|
|
61
|
+
A client must send appropriate HTTP header `Accept`. As only JSON is by now built-in
|
|
62
|
+
in HaveAPI, it should send `application/json`.
|
|
63
|
+
|
|
64
|
+
## Authentication
|
|
65
|
+
All authentication methods that are built-in the HaveAPI should be supported
|
|
66
|
+
if possible. The client should choose suitable authentication method
|
|
67
|
+
for its purpose and allow the developer to select the authentication method
|
|
68
|
+
if it makes sense to do so.
|
|
69
|
+
|
|
70
|
+
It is a good practise to implement authentication methods as plugins,
|
|
71
|
+
so that developers may add custom authentication providers easily.
|
|
72
|
+
|
|
73
|
+
## Object-like access
|
|
74
|
+
A client must interpret the API response according to action output layout.
|
|
75
|
+
Layouts `object` and `object_list` should be handled as object instances,
|
|
76
|
+
if the language allows it.
|
|
77
|
+
|
|
78
|
+
Object instances represent the object fetched from the database. Received
|
|
79
|
+
parameters are accessed via object attributes/properties. Actions are defined
|
|
80
|
+
as instance methods. Objects may have associations to other resources which
|
|
81
|
+
must be made available and be easy to access.
|
|
82
|
+
|
|
83
|
+
# Supplemental features
|
|
84
|
+
Following features are supplemental. It is good to support them,
|
|
85
|
+
but is not necessary.
|
|
86
|
+
|
|
87
|
+
## Client-side validations
|
|
88
|
+
Client may make use of described validators and validate the input before
|
|
89
|
+
sending it to the API, to lessen the API load and make it more user-friendly.
|
|
90
|
+
|
|
91
|
+
However, as the input is validated on the server anyway, it does not have
|
|
92
|
+
to be implemented.
|
|
93
|
+
|
|
94
|
+
## Metadata channel
|
|
95
|
+
Metadata channel is currently used to specify what associated resources should
|
|
96
|
+
be prefetched and whether an object list should contain total number of items.
|
|
97
|
+
|
|
98
|
+
Metadata is nothing more than a hash in input parameters under key `_meta`.
|
|
99
|
+
|
|
100
|
+
## Blocking actions
|
|
101
|
+
Useful for APIs with long-running actions. Clients can check state of such actions
|
|
102
|
+
using resource `ActionState`. Because this resource is automatically present in all
|
|
103
|
+
APIs that use blocking actions, client libraries expose this resource to the developer
|
|
104
|
+
just as any other resource in the API.
|
|
105
|
+
|
|
106
|
+
However, you may wish to integrate it in your client and provide ways for the action
|
|
107
|
+
call to block/accept callbacks.
|