Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays committed Aug 26, 2023
1 parent 433e8e0 commit 590827b
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,140 @@ An asynchronous Rust SDK for the [Unkey API](https://docs.unkey.dev/introduction

The minimum supported Rust verision for the project is `1.63.0`.

## Documentation

Full documentation can be found at [https://docs.rs/unkey](https://docs.rs/unkey).

## Setup

Add the following to your `Cargo.toml` [dependencies]

```toml
unkey = "0.1"
```

## Examples

### Verifying a key

```rs
use unkey::models::{VerifyKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
let c = Client::new("unkey_ABC");
let req = VerifyKeyRequest::new("test_DEF");

match c.verify_key(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}
}
```

### Creating a key

```rs
use unkey::models::{CreateKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
let c = Client::new("unkey_ABC");
let req = CreateKeyRequest::new("api_123")
.set_prefix("test")
.set_remaining(100)
.set_name("test_name")
.set_owner_id("jonxslays");

match c.create_key(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}
}
```

### Updating a key

```rs
use unkey::models::{UpdateKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
let c = Client::new("unkey_ABC");
let req = UpdateKeyRequest::new("key_XYZ")
.set_name(Some("new_name")) // Update the keys name
.set_ratelimit(None); // Remove any ratelimit on the key

match c.update_key(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}
}
```

### Revoking a key

```rs
use unkey::models::{RevokeKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
let c = Client::new("unkey_ABC");
let req = RevokeKeyRequest::new("key_XYZ");

match c.revoke_key(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}
}
```

### Listing api keys

```rs
use unkey::models::{ListKeysRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
let c = Client::new("unkey_ABC");
let req = ListKeysRequest::new("api_123");

match c.list_keys(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}
}
```

### Getting api information

```rs
use unkey::models::{GetApiRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
let c = Client::new("unkey_ABC");
let req = GetApiRequest::new("api_123");

match c.get_api(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}
}
```

## Contributions

Unkey for Rust is open to contributions! Check out the
[contributing guide](https://github.com/Jonxslays/unkey/blob/master/CONTRIBUTING.md)
to get started.

## License

Unkey for Rust is licensed under the
Expand Down

0 comments on commit 590827b

Please sign in to comment.