Skip to content

generate an executable to manipulate your HTTP API from CLI

License

Notifications You must be signed in to change notification settings

djedi23/crud.rs

Repository files navigation

CRUD

A rust workspace to create command line interfaces (CLI) to HTTP API.

For example, you can create a CLI for jsonplaceholder with this sniplet:

#[derive(Debug, Crud, Deserialize, Serialize, Default)]
struct Posts {
  #[crud(id, no_short)]
  id: u32,
  #[crud(help = "post author's id")]
  #[serde(rename = "userId")]
  user_id: u32,
  #[crud(help = "title of the post")]
  #[crud(no_short)]
  title: String,
  #[crud(help = "body of the post")]
  body: String,
}

After compiling (and some boitlerplates; uses, main function, ...), you'll obtain:

$ jsonplaceholder posts -h
Posts listing

Usage: jsonplaceholder posts [OPTIONS] [id] [COMMAND]

Commands:
  create    Posts creation
  delete    Posts deletion
  update    Posts update
  replace   Posts replacement
  help      Print this message or the help of the given subcommand(s)

Arguments:
  [id]

Options:
  -h, --help  Print help information (use `--help` for more detail)
$ jsonplaceholder posts create -h
Posts creation

Usage: jsonplaceholder posts create [OPTIONS] --user_id <user_id> --title <title> --body <body>

Options:
  -h, --help  Print help information (use `--help` for more detail)

Payload:
  -u, --user_id <user_id>  post author's id
      --title <title>      title of the post
  -b, --body <body>        body of the post

The complete code of this example is at ./crud/examples/jsonplaceholder.rs

Sub Crates

About

generate an executable to manipulate your HTTP API from CLI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages