2020-11-04 20:31:15 +01:00
# Iris JWT Tutorial
2020-11-05 09:47:56 +01:00
This example show how to use JWT with domain-driven design pattern with Iris. There is also a simple Go client which describes how you can use Go to authorize a user and use the server's API.
## Run the server
2020-11-04 20:31:15 +01:00
```sh
$ go run main.go
```
2020-11-05 09:47:56 +01:00
## Authenticate, get the token
2020-11-04 20:31:15 +01:00
```sh
$ curl --location --request POST 'http://localhost:8080/signin' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'username=admin' \
--data-urlencode 'password=admin'
> $token
```
2020-11-05 09:47:56 +01:00
## Get all TODOs for this User
2020-11-04 20:31:15 +01:00
```sh
$ curl --location --request GET 'http://localhost:8080/todos' \
--header 'Authorization: Bearer $token'
> $todos
```
2020-11-05 09:47:56 +01:00
## Get a specific User's TODO
2020-11-04 20:31:15 +01:00
```sh
$ curl --location --request GET 'http://localhost:8080/todos/$id' \
--header 'Authorization: Bearer $token'
> $todo
```
2020-11-05 09:47:56 +01:00
## Get all TODOs for all Users (admin role)
2020-11-04 20:31:15 +01:00
```sh
$ curl --location --request GET 'http://localhost:8080/admin/todos' \
--header 'Authorization: Bearer $token'
> $todos
```
2020-11-05 09:47:56 +01:00
## Create a new TODO
2020-11-04 20:31:15 +01:00
```sh
$ curl --location --request POST 'http://localhost:8080/todos' \
--header 'Authorization: Bearer $token' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "test titlte",
"body": "test body"
}'
> Status Created
> $todo
```