1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
//! # Webwire command-line Interface
//!
//! [![Crates.io](https://img.shields.io/crates/v/webwire-cli)](https://crates.io/crates/webwire-cli)
//! [![GitHub](https://img.shields.io/github/license/webwire/webwire-cli)](https://github.com/webwire/webwire-cli/blob/master/LICENSE)
//! [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/webwire/webwire-cli/Rust)](https://github.com/webwire/webwire-cli/actions)
//!
//! [![Discord Chat](https://img.shields.io/discord/726922033039933472?label=Discord+Chat&color=%23677bc4&logo=discord&logoColor=white&style=for-the-badge)](https://discord.gg/jjD6aWG)
//!
//! ![webwire logo](https://webwire.dev/logo.svg)
//!
//! Webwire is a **contract-first API system** which features an
//! interface description language a network protocol and
//! code generator for both servers and clients.
//!
//! This repository contains the the **command-line interface** used
//! to validate Webwire IDL files and generate code and documentation.
//!
//! To learn more about webwire in general please visit the documentation
//! repository [webwire/webwire-docs](https://github.com/webwire/webwire-docs).
//!
//! # Example
//!
//! The following example assumes a Rust server and a TypeScript client. Webwire
//! is by no means limited to those two but those languages show the potential of
//! webwire best.
//!
//! Given the following IDL file:
//!
//! ```webwire
//! webwire 1.0;
//!
//! struct HelloRequest {
//!     name: String,
//! }
//!
//! struct HelloResponse {
//!     message: String,
//! }
//!
//! service Hello {
//!     hello: HelloRequest -> HelloResponse
//! }
//! ```
//!
//! The server and client files can be generated using the code generator:
//!
//! ```bash
//! $ webwire gen rust server api/hello.ww server/src/api.rs
//! $ webwire gen ts client api/hello.ww client/src/api.ts
//! ```
//!
//! A Rust server implementation for the given code would look like this:
//!
//! ```rust,ignore
//! use std::net::SocketAddr;
//! use webwire::{Context, Request, Response}
//! use webwire::hyper::Server;
//!
//! mod api;
//! use api::v1::{Hello, HelloRequest, HelloResponse}; // this is the generated code
//!
//! struct HelloService {}
//!
//! impl Hello for HelloService {
//!     fn hello(&self, ctx: &Context, request: &HelloRequest) -> HelloResponse {
//!         HelloResponse {
//!             message: format!("Hello {}!", request.name)
//!         }
//!     }
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error> {
//!     let addr = SocketAddr::from(([127, 0, 0, 1], 8000));
//!     let service = HelloService {};
//!     let server = webwire::Server::bind(addr).serve(service);
//!     server.await
//! }
//! ```
//!
//! A TypeScript client using the generated code would look like that:
//!
//! ```typescript
//! import { Client } from 'api/v1' // this is the generated code
//!
//! client = new Client('http://localhost:8000/')
//! const response = await client.hello({ name: 'World' })
//! assert(response.message === 'Hello World!')
//! ```
//!
//! ## License
//!
//! Licensed under either of
//!
//! - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0)>
//! - MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT)>
//!
//! at your option.
pub mod codegen;
pub mod common;
pub mod idl;
pub mod schema;