]>
Commit | Line | Data |
---|---|---|
b0ca5dae RBR |
1 | --- title: /api.html |
2 | --- description: API Notation | |
f752d89a | 3 | ## API Notation |
b0ca5dae | 4 | |
12629849 | 5 | API Notation is a language-agnostic notation to share the public API of components in code. It was created to standardize software specification documents in teams that need to review code across several languages. |
b0ca5dae | 6 | |
f752d89a RBR |
7 | ## Reference |
8 | The notation allows describing objects or modules, with properties, events and methods along with their types. | |
bfaa6658 RBR |
9 | ``` |
10 | // Anything after two forward slashes is a comment | |
11 | NameOfClass.WithPossibleNamespace | |
12 | + class property | |
13 | - instance property | |
14 | ~> listened events (socket) | |
15 | +> listened events (class/module) | |
16 | -> listened events (instance) | |
17 | <~ dispatched events (socket) | |
18 | <+ dispatched events(class/module) | |
19 | <- dispatched events (instance) | |
20 | :: class method | |
21 | # instance method | |
f752d89a | 22 | ---- |
bfaa6658 RBR |
23 | Other symbols |
24 | => returns | |
25 | #> throws | |
26 | [xx] optional | |
27 | <xx> data type | |
bfaa6658 RBR |
28 | ``` |
29 | ||
f752d89a RBR |
30 | ## Example |
31 | With this artificial example, you can see how to use it for more complex cases: | |
b0ca5dae | 32 | |
b0ca5dae | 33 | ``` |
12629849 RBR |
34 | // Definitions start with object / module / class names, with namespaces |
35 | // separated by periods. Types are marked between angular brackets. | |
36 | Definitions.Models.Post | |
37 | // Properties. | |
f752d89a RBR |
38 | +static_property <Type> |
39 | -instance_property <Types<Can<Be<Nested>>>> | |
12629849 RBR |
40 | // Methods. Parameters are listed in parentheses, and comma separated. |
41 | // Optional values are inside brackets | |
42 | // => defines return values | |
43 | // #> defines thrown exceptions, can be comma separated. | |
f752d89a RBR |
44 | ::static_methods(parameter_label <Type>) => ReturnValueType #> BadTimesException,UnknownError |
45 | #update(text <String>, [options] <GlobalOptions.tOptions>) => Promise<Void> | |
46 | // Function types can include parameter lists, returns and throws as well. | |
47 | #transform<T>( Function<T>(payload <T>) => <T>, announce <Bool>) => <Bool> | |
12629849 | 48 | // Listened Events |
f752d89a | 49 | +>static_listener(parameters_expected <Bool>) |
12629849 | 50 | ->instance_listener() |
f752d89a | 51 | ~>network_events(peer <Networking.Peer>) |
12629849 | 52 | // Emitted Events |
f752d89a RBR |
53 | <+emitted_statically(payload <StaticEventPayload>) |
54 | <-emitted_by_instance(reason <String>, code <Int>) | |
55 | <~emitted_through_network(text <String>) | |
b0ca5dae | 56 | ``` |