MIDGARD
Midgard is a REST API code generator. The ultimate goal of Midgard is to generate, from a single JSON object describing the models, a REST API in any languages and frameworks possible. To do its generation, Midgard needs a service file per languages / frameworks. The service file describe how the API should be generated (see below). When you have a service file for the language you want to generate a REST API in, all you have to do is to call Midgard with your models file (see below).
INSTALL
sudo npm install -g Midgard (it currently only works well on linux environments)
Since Midgard is a command line tool, it should be installed globally.
Midgard uses a certain directory structure and it won't be created automatically when you install Midgard (you'll have to do it manually).This is what the directory in which Midgard has been installed should look like:
├── bin│ └── indexjs├── makefile├── node_modules│ ├── es6-module-loader│ ├── handlebars│ ├── mkdirp│ ├── q│ ├── traceur│ └── underscore├── packagejson├── READMEmd├── services├── serviceTemplates│ └── translators├── src│ └── compilerjs└── test └── compilerSpecjs
SERVICE FILE
A service file is a description of what will be generated and how it will be generated. The service file is basically just an annoted class that we export.
@ {};
The command in the executePre and executePost properties will be executed sequentially so a command can depend on another.
The files are generated either with HandlebarsJS or with a ES6 template literal.
MODELS FILE
Like a service file, a models file is an annoted class with a call to the generator's start function.
@ {}
The first object in the model array is the server node. It contains, well..., server informations like the host, the port and the url.
The second object is the service node. This is where we indicate which kind of service we're generating (i.e the service file). Database credential such as the adapter, dsn, user and password are service dependant (they change depending) on wich type of service we're generating) so they will appear in the service node.
The third object (and all those after it) are the collection nodes. This is where you describe the models of your application (collections for mongodb or tables for relational database)
No extensive documentation has been made yet for the on the content of the nodes. Please refer to unit tests for examples of what is possible.
EXECUTING
Once that your Midgard directory structure is set up and that you have a a service and a models file all you have to do to generate your REST API is to execute the following command:
Midgard path/to/models.file
SERVICE FILE EXAMPLE
This is an example of what a service file could/should look like. This service file is what has been use in the latest integration tests of Midgard and serves to generate a REST API for a silex/propel environment. Note that this service file is not fully completed...
@ {};
MODELS FILE EXAMPLE
This is an example of what a models file could/should look like. This models file is what has been use in the latest integration tests of Midgard and serves to generate a REST API for a silex/propel environment. Note that this models file is not fully completed...
; @ {};