Pdef compiler
Project description
Pdef - Interface definition language for the web
================================================
Pdef (pi:def, stands for "protocol definition [language]") is a statically typed interface
definition language which supports JSON and a simple HTTP RPC. It allows to write
interfaces and data structures once and then to generate code and RPC clients/servers for
different languages. It is suitable for public APIs, internal service-oriented APIs,
configuration files, as a format for persistence, cache, message queues, logs, etc.
Features:
- Packages, modules, imports and namespaces.
- Circular module imports and type references (with some limitations).
- Simple type system built on a clear separation between data structures and interfaces.
- Message and interface inheritance.
- Chained method invocations.
- Default JSON format and HTTP RPC.
- Pluggable loosely-coupled formats and RPCs.
- Pluggable code generators.
Languages
---------
- [Java](https://github.com/pdef/pdef-java)
- [Python](https://github.com/pdef/pdef-python)
- [Objective-C](https://github.com/pdef/pdef-objc)
Links
-----
- **[Language guide](docs/language-guide.md)**
- [Style guide](docs/style-guide.md)
- [JSON format](docs/json-format.md)
- [HTTP RPC](docs/http-rpc.md)
- [Grammar in BNF](docs/grammar.bnf)
- [Generated and language specific code](docs/generated-lang-specific-code.md)
- [How to write a code generator](https://github.com/pdef/pdef-generator-template)
- [Google group](https://groups.google.com/d/forum/pdef) (pdef@googlegroups.com)
Requirements
------------
- The compiler requires Python 2.7 or Python 3.3.
- Bindings requirements are language specific.
Installation
------------
Pdef consists of a compiler, pluggable code generators, and language-specific bindings.
Install the compiler as a python package:
```bash
python setup.py install
```
Install the code generators:
```bash
pip install pdef-python
pdefc check https://raw.github.com/pdef/pdef/master/example/world.yaml
```
Getting Started
---------------
Create a package file `myproject.yaml`
```yaml
package:
name: myproject
modules:
- posts
- photos
```
Create the module files:
`posts.pdef`
```pdef
namespace myproject;
import myproject.photos;
interface Posts {
get(id int64) Post;
@post
create(title string, text string) Post;
}
message Post {
id int64;
title string;
text string;
photos list<Photo>;
}
```
`photos.pdef`
```pdef
namespace myproject;
message Photo {
id int64;
url string;
}
```
Generate the source code:
```bash
pdefc generate-objc myproject.yaml --out generated/
curl -d human="{\"id\": 1, \"name\":\"John\"}" http://example.com/world/humans/create
{
"data": {
"id": 1,
"name": "John"
}
}
```
Switch the light:
```bash
curl "http://example.com/world/humans/all?limit=2&offset=10"
{
"data": [
{"id": 11, "name": "John"},
{"id": 12, "name": "Jane"}
]
}
```
License and Copyright
---------------------
Copyright: 2013 Ivan Korobkov <ivan.korobkov@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
Pdef (pi:def, stands for "protocol definition [language]") is a statically typed interface
definition language which supports JSON and a simple HTTP RPC. It allows to write
interfaces and data structures once and then to generate code and RPC clients/servers for
different languages. It is suitable for public APIs, internal service-oriented APIs,
configuration files, as a format for persistence, cache, message queues, logs, etc.
Features:
- Packages, modules, imports and namespaces.
- Circular module imports and type references (with some limitations).
- Simple type system built on a clear separation between data structures and interfaces.
- Message and interface inheritance.
- Chained method invocations.
- Default JSON format and HTTP RPC.
- Pluggable loosely-coupled formats and RPCs.
- Pluggable code generators.
Languages
---------
- [Java](https://github.com/pdef/pdef-java)
- [Python](https://github.com/pdef/pdef-python)
- [Objective-C](https://github.com/pdef/pdef-objc)
Links
-----
- **[Language guide](docs/language-guide.md)**
- [Style guide](docs/style-guide.md)
- [JSON format](docs/json-format.md)
- [HTTP RPC](docs/http-rpc.md)
- [Grammar in BNF](docs/grammar.bnf)
- [Generated and language specific code](docs/generated-lang-specific-code.md)
- [How to write a code generator](https://github.com/pdef/pdef-generator-template)
- [Google group](https://groups.google.com/d/forum/pdef) (pdef@googlegroups.com)
Requirements
------------
- The compiler requires Python 2.7 or Python 3.3.
- Bindings requirements are language specific.
Installation
------------
Pdef consists of a compiler, pluggable code generators, and language-specific bindings.
Install the compiler as a python package:
```bash
```
Install the code generators:
```bash
```
Getting Started
---------------
Create a package file `myproject.yaml`
```yaml
package:
name: myproject
modules:
- posts
- photos
```
Create the module files:
`posts.pdef`
```pdef
namespace myproject;
import myproject.photos;
interface Posts {
get(id int64) Post;
@post
create(title string, text string) Post;
}
message Post {
id int64;
title string;
text string;
photos list<Photo>;
}
```
`photos.pdef`
```pdef
namespace myproject;
message Photo {
id int64;
url string;
}
```
Generate the source code:
```bash
{
"data": {
"id": 1,
"name": "John"
}
}
```
Switch the light:
```bash
{
"data": [
{"id": 11, "name": "John"},
{"id": 12, "name": "Jane"}
]
}
```
License and Copyright
---------------------
Copyright: 2013 Ivan Korobkov <ivan.korobkov@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.