UNPKG

json-api-schema

Version:

JSON Api Schema is a JSON dialect that can describe any Web Based API that uses JSON to exchange data.

86 lines (45 loc) 3.82 kB
# JSON Api Schema ## A Json based Web API Description Language and Object Model __JSON Api Schema__ is a JSON dialect ( just a json file ) that can describe any Web Based API that uses JSON to exchange data. A __JSON Api Schema__ can be used to share an unabiguous object model between servers and clients along with validation logic, classes and so on. In other words __JSON Api Schema__ is a set of two related specification: - __JSON Api Schema-DL__: A JSON API Description Language - __JSON Api Schema-OM__: A related API Object Model (similar of what DOM is to HTML) ### Design goals #### Be generic enough to describe complex systems __JSON Api Schema__ is designed to express a generic API minimizing constraints on implementations. __JSON Api Schema__ Description Language can support applicaition specific behaviours through extensions. JSON Api Schema is designed to be able to express a super-set of RESTful APIs and JSON APIs, as a mean to communicate interactions and data structures exposed by an API. Application specific stuffs are expressed through protocol options. #### Be available in multiple languages __JSON Api Schema__ Object Model adopt conventions that make it easy to be implemented in most languages. For example we use getters and setters over properties and accessors, iterators instead of closures, ecc... #### Be suitable to readapt existing data models Being easy to implement in both clients and servers __JSON Api Schema__ is perfect to renew an old data source. #### Be a real-world solution To be different from other well known solution it primarly targets modern web development (A Javascript friendly solution, easy to map validation errors to form fields, support for websockets, EventSources ecc..., and more over not be a two billion SLOC framework). #### Allow to share validation logic between servers and clients __JSON Api Schema__ heavily relies on JSON Schema to export validation logic to clients. #### Be suitable to build RMI on top of it Implementing Types __JSON Api Schema__ makes it easy (but not forces) to hide network requests behind OOP objects and classes. #### Be documentable __JSON Api Schema__ support documentation attributes everywhere. A traversable model make it easy to generate a beautiful readable documentation. ### A typical use case An application consists of a data api, a website and a mobile app: - They are 3 separate systems that may be written in different languages. - They shares the same domain model. Data Api exports its interface through __JSON Api Schema__. Website and Mobile App consumes that through dynamically or statically generated stubs, or either by directly calling actions via ajax requests. ## Specification ### Api Model (For Both DL and OM): #### Api The entry point of the model. An Api is a set of interactions, types and resources. An api exposes also protocol specific global informations to configure interactions. #### Resource A Resource is a type that has interactions. A Resource can have nested resources. Nested resources are somewhat logically bound to their container, eg. by ID or by URI. #### Schema A JSON Schema instance. Anything that can be validated should have or be a schema. #### Type Just a named `Schema`. #### Interactions An interaction is a communication available with the api. It can represent both a client-initiated communication or a server initiated communication. Protocol based informations about an interaction are stored in a `protocols` map. ##### Action An action is a client initiated interaction. It has two validatable sub-entities along with protocol specification: `params` and `returns` ##### Event An event is a server initiated interaction. It has a validatable sub-entity along with protocol specification: `params`.