This repository has been archived by the owner. It is now read-only.
A web service definition format and source code generator.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cedar
examples/todos
tests
.gitignore
.travis.yml
LICENSE
MANIFEST.in
README.md
requirements.txt
requirements_dev.txt
setup.cfg
setup.py

README.md

cedar PyPI version Build Status Coverage Status Codacy Badge

This is alpha-level stuff.

Cedar is a small web service declaration language. You declare your service using this language and then use that declaration to generate client and server code for a number of programming languages.

Goals

  • A single transport (http) and serialization format (json).
  • Simple, consolidated tooling. All functionality must live under this repository and must be distributed under one package.
  • Aim to be an 85% solution. Be the most simple thing that covers the widest array of use cases. Never add complexity for the sake of covering fringe use cases.
  • Generated source code must be idiomatic to the generated language.
  • Generated source code must be human-readable.

Installation

pip3 install cedar

Languages

Cedar currently targets Elm (clients) and Go (servers) source code.

Go

cedar generate go --help

Requirements

Generated Go code has no external dependencies, but it does require at least Go version 1.6.

Elm

cedar generate elm --help

Requirements

Generated Elm code currently requires Elm 0.17 and the following packages:

The Cedar language

A Cedar specification consists of one or more toplevel declarations. All toplevel declarations must be valid enums, unions, records or fns.

Example

enum Role { User, Mod, Admin }

record User {
  id Int
  email String
  role Role
}

fn getUsers() [User]
fn getUser(id Int) User?
fn deleteUser(id Int) Bool

Types

There are 5 builtin types: Bool, Int, Float, String and Timestamp.

List types are declared using the [t] syntax (eg. [String]), dict types are declared using the {String: t} syntax, and nullable types are declared using the t? syntax.

Enums

enum Status { Ready, Done, Failed }

Enums introduce new types (named after the enum) whose values are constrained to the tags defined in the enum. The tags inside an enum are serialized as strings. For example, a record attribute with the type Status can contain one of the following JSON values: "Ready", "Done" and "Failed".

Unions

union Resource { Post, Comment }

Unions join multiple types under a single new type.

Records

record Post {
  id Int
  title String
  content String
  publishedAt Timestamp
}

Functions

fn createPost(title String, content String, publishedAt Timestamp?) Post

Editor support