https://github.com/dbackowski/dry-rb-api-example
Simple example of rails application for API using some of dry-rb gems
https://github.com/dbackowski/dry-rb-api-example
Last synced: 5 months ago
JSON representation
Simple example of rails application for API using some of dry-rb gems
- Host: GitHub
- URL: https://github.com/dbackowski/dry-rb-api-example
- Owner: dbackowski
- Created: 2022-04-23T15:51:33.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-04-25T07:21:33.000Z (about 4 years ago)
- Last Synced: 2024-12-29T12:40:56.009Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Simple example of rails application for API using some dry-rb gems like:
- dry-validation
- dry-monads
- dry-matcher
- dry-struct
Run in the console:
```
rails s
```
Next you can play with it using curl command, examples:
- with valid params
```
curl -d '{"first_name":"John", "last_name":"Doe"}' -H "Content-Type: application/json" -H "Authorization: Bearer XXX" -X POST http://localhost:3000/tokens.json | jq
```
```
{
"first_name": "John",
"last_name": "Doe"
}
```
- with invalid params
```
curl -d '{"last_name":"Doe"}' -H "Content-Type: application/json" -H "Authorization: Bearer XXX" -X POST http://localhost:3000/tokens.json | jq
```
```
{
"errors": {
"first_name": [
"is missing"
]
}
}
```
- with missing authorization header
```
curl -v -d '{"first_name":"John", "last_name":"Doe"}' -H "Content-Type: application/json" -X POST http://localhost:3000/tokens.json | jq
```
```
> POST /tokens.json HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 40
>
} [40 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 403 Forbidden
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 0
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: strict-origin-when-cross-origin
< Content-Type: application/json
< Cache-Control: no-cache
< X-Request-Id: 5b4f0986-de9c-473d-a1da-a2210a8ad1aa
< X-Runtime: 0.004600
< Server-Timing: start_processing.action_controller;dur=0.070068359375, process_action.action_controller;dur=0.21484375
< Transfer-Encoding: chunked
```