-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add doc comments and update readme
- Loading branch information
1 parent
157e1c2
commit b4e0fd4
Showing
3 changed files
with
269 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
*.ez | ||
build | ||
erl_crash.dump | ||
src/example.gleam |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,41 @@ | ||
# gwt | ||
|
||
Encode and decode JWTs. | ||
|
||
[![Package Version](https://img.shields.io/hexpm/v/gwt)](https://hex.pm/packages/gwt) | ||
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gwt/) | ||
|
||
## Quick start | ||
## Quickstart | ||
|
||
```sh | ||
gleam run # Run the project | ||
gleam test # Run the tests | ||
gleam shell # Run an Erlang shell | ||
```gleam | ||
import gwt.{type Jwt, type Verified, type Unverified} | ||
pub fn main() { | ||
let jwt = | ||
gwt.new() | ||
|> gwt.set_subject("1234567890") | ||
|> gwt.set_audience("0987654321") | ||
|> gwt.set_not_before(1_704_043_160) | ||
|> gwt.set_expiration(1_704_046_160) | ||
|> gwt.set_jwt_id("2468") | ||
let jwt_without_signature = gwt.to_string(jwt) | ||
let jwt_with_signature = gwt.to_signed_string(jwt, gwt.HS256, "lucy") | ||
let assert Ok(unverified_jwt) = | ||
jwt_without_signature | ||
|> gwt.from_string() | ||
let assert Ok(verified_jwt) = | ||
jwt_with_signature | ||
|>gwt.from_signed_string("lucy") | ||
} | ||
``` | ||
|
||
## Installation | ||
|
||
If available on Hex this package can be added to your Gleam project: | ||
|
||
```sh | ||
gleam add gwt | ||
gleam add gwt | ||
``` | ||
|
||
and its documentation can be found at <https://hexdocs.pm/gwt>. | ||
The documentation can be found at <https://hexdocs.pm/gwt>. |
Oops, something went wrong.