X-Git-Url: https://git.r.bdr.sh/rbdr/r.bdr.sh/blobdiff_plain/bfaa66583b3210ad6da796a26f20e601c03275e4..842364af84b295114b4c6f2d42fb6a1c51dd17ad:/api.gmi diff --git a/api.gmi b/api.gmi index d0d99ad..60cc62a 100644 --- a/api.gmi +++ b/api.gmi @@ -1,9 +1,11 @@ --- title: /api.html --- description: API Notation -# API Notation +## API Notation 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. +## Reference +The notation allows describing objects or modules, with properties, events and methods along with their types. ``` // Anything after two forward slashes is a comment NameOfClass.WithPossibleNamespace @@ -17,45 +19,38 @@ NameOfClass.WithPossibleNamespace <- dispatched events (instance) :: class method # instance method - +---- Other symbols => returns #> throws [xx] optional data type - -Recommended order: class first, then sockets, then instance. Internally: -Properties, events, methods. ``` -Or, with some examples: +## Example +With this artificial example, you can see how to use it for more complex cases: ``` // Definitions start with object / module / class names, with namespaces // separated by periods. Types are marked between angular brackets. Definitions.Models.Post // Properties. - +static_property - -instance_property >>> + +static_property <Type> + -instance_property <Types<Can<Be<Nested>>>> // Methods. Parameters are listed in parentheses, and comma separated. // Optional values are inside brackets // => defines return values // #> defines thrown exceptions, can be comma separated. - ::static_methods(parameter_label ) => ReturnValueType #> BadTimesException,UnknownError - #update(text , [options] ) => Promise + ::static_methods(parameter_label <Type>) => ReturnValueType #> BadTimesException,UnknownError + #update(text <String>, [options] <GlobalOptions.tOptions>) => Promise<Void> + // Function types can include parameter lists, returns and throws as well. + #transform<T>( Function<T>(payload <T>) => <T>, announce <Bool>) => <Bool> // Listened Events - +>static_listener(parameters_expected ) + +>static_listener(parameters_expected <Bool>) ->instance_listener() - ~>network_events(peer ) + ~>network_events(peer <Networking.Peer>) // Emitted Events - <+emitted_statically(payload ) - <-emitted_by_instance(reason , code ) - <~emitted_through_network(text ) -``` - -When defining function types, you may use parameter lists, returns and throws notation as well. - -``` -HypotheticalModule - #transform( Function(payload ) => , announce ) => + <+emitted_statically(payload <StaticEventPayload>) + <-emitted_by_instance(reason <String>, code <Int>) + <~emitted_through_network(text <String>) ```