Skip to content

rust sdk docs 🦀 🐰 📜 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.next
node_modules
.idea
3 changes: 2 additions & 1 deletion mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
{
"group": "Go",
"pages": ["sdks/server/go-api", "sdks/server/go-leap"]
}
},
"sdks/server/rs"
]
}
]
Expand Down
12 changes: 12 additions & 0 deletions reference/project-tokens.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ func main() {
}
````

```rs Rust
extern crate hop;

use hop::Hop;

#[tokio::main]
async fn main() {
let my_token = "ptk_xxx";
let hop = Hop::new(my_token);
}
````

</CodeGroup>

### API
Expand Down
1 change: 1 addition & 0 deletions sdks/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ languages. Below is a list of our official, supported libraries.
| ---------- | ---------- | ------------------------------------------------------------------------ | -------- | ------------------------------------------ |
| @onehop/js | TypeScript | [npmjs.com/package/@onehop/js](https://www.npmjs.com/package/@onehop/js) | ✅ | [/sdks/server/js](/sdks/server/js) |
| hop-go | Golang | [github.com/hopinc/go](https://github.com/hopinc/go) | ✅ | [/sdks/server/go-api](/sdks/server/go-api) |
| hop-rs | Rust | [github.com/hopinc/rs](https://github.com/hopinc/rs) | ✅ | [/sdks/server/rs-api](/sdks/server/rs-api) |

### REST API

Expand Down
43 changes: 43 additions & 0 deletions sdks/server/rs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: 'Server-side Rust SDK'
sidebarTitle: 'Rust'
description:
'The Hop server-side Rust SDK allows you to interact with all Hop products on
the server side.'
---

## Installing

You can add `hop-rs` to your `cargo.toml` file:

```toml TOML
[dependencies]
hop-rs = "0.1.0"
```

## Creating an SDK Instance

To use the SDK, you must first create a
[project token](/reference/project-tokens). You can also use a PAT (personal
access token), however this is not recommended as it has access to all of your
projects.

```rust RS
extern crate hop;
extern crate rand;

use hop::Hop;
use rand::Rng;

#[tokio::main]
async fn main() {
let my_token = "ptk_xxx";
let hop = Hop::new(my_token);

// Example: Creating a project secret
hop.projects.create_secret(
"RANDOM_NUMBER",
rand::thread_rng().gen_range(0..100).to_string(),
).await.unwrap();
}
```