chyabrung-cli 0.2.4

The `chy` command line tool for Chyabrung: scaffolding, dev server with hot reload, builds, generators, migrations and one-command deploys
//! # Responses: how your data looks in the API output
//!
//! `requests/` describes what comes **in**; this folder describes what goes
//! **out**. A resource turns a model into the JSON your API sends, so you
//! decide exactly which fields clients see (and never leak a password hash):
//!
//! ```ignore
//! #[resource(Post)]
//! pub struct PostResource;
//!
//! impl JsonResource for PostResource {
//!     fn to_array(&self) -> JsonValue {
//!         json!({
//!             "id": self.id,                                      // `self` reads the Post
//!             "title": self.title,
//!             "author": UserResource::when_loaded(&self.author),  // only when loaded
//!             "body": when(self.published, &self.body),           // only when published
//!         })
//!     }
//! }
//! ```
//!
//! In a controller:
//!
//! | Return                                  | JSON                                         |
//! |-----------------------------------------|----------------------------------------------|
//! | `PostResource::make(post)`              | `{"data": {...}}`                            |
//! | `PostResource::make(post).created()`    | the same, with status `201 Created`          |
//! | `PostResource::collection(posts)`       | `{"data": [...]}`                            |
//! | `PostResource::collection(page)`        | `{"data": [...], "links": {...}, "meta": {...}}` for `.paginate()` |
//! | `.additional(json!({ "meta": {...} }))` | extra top-level fields next to `data`        |
//!
//! - Create a new one with `chy make:response Comment`. It is added to this
//!   file for you.
//! - Optional fields: `when(condition, value)`, `merge_when(condition, json!({...}))`,
//!   `OtherResource::when_loaded(&self.relation)`.
//! - Errors keep their own format (`{"error": {...}}`); you don't need a resource for them.

pub mod post_resource;
pub mod user_resource;

pub use post_resource::PostResource;
pub use user_resource::UserResource;