Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SuperPaintman/request-id
Middleware for generates / pick up a unique request ID for Crystal servers.
https://github.com/SuperPaintman/request-id
kemal middleware request-id
Last synced: about 1 month ago
JSON representation
Middleware for generates / pick up a unique request ID for Crystal servers.
- Host: GitHub
- URL: https://github.com/SuperPaintman/request-id
- Owner: SuperPaintman
- License: mit
- Created: 2017-02-08T19:17:57.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-18T08:29:02.000Z (over 6 years ago)
- Last Synced: 2024-08-01T17:35:28.712Z (4 months ago)
- Topics: kemal, middleware, request-id
- Language: Crystal
- Size: 13.7 KB
- Stars: 8
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - request_id - Middleware for generates / pick up a unique request ID for Crystal servers (Framework Components)
- awesome-crystal - request_id - Middleware for generates / pick up a unique request ID for Crystal servers (Framework Components)
README
# request\_id
[![Linux Build][travis-image]][travis-url]
[![Shards version][shards-image]][shards-url]Middleware for generates / pick up a unique request ID for **Crystal** servers.
This module set response HTTP Header like this:
> X-Request-ID: 753a468b-4179-40c4-bb58-ff508cb39d67
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
request_id:
github: SuperPaintman/request-id
```--------------------------------------------------------------------------------
## Usage
### With pure Crystal server```crystal
require "request_id"
require "http/server"server = HTTP::Server.new("0.0.0.0", 8080,
[
RequestID::Handler.new
]) do |context|
context.response.content_type = "text/plain"
context.response.print "Hello request id!"
endserver.listen
```### With Kemal
```crystal
require "request_id"
require "kemal"add_handler RequestID::Handler.new
get "/" do |env|
"Hello request id!"
endKemal.run
```### Custom Generator
> By default: `uuid`
```crystal
require "request_id"
require "http/server"class CustomRequestIDHandler < RequestID::Handler
def generator
"custom_request_id_generator"
end
endserver = HTTP::Server.new("0.0.0.0", 8080,
[
CustomRequestIDHandler.new
]) do |context|
context.response.content_type = "text/plain"
context.response.print "Hello request id!"
endserver.listen
```--------------------------------------------------------------------------------
## Examples
### Random ID```sh
curl -I localhost:8080
# HTTP/1.1 200 OK
# X-Request-ID: 5e3df631-85e6-4eaf-bb1c-68375291332e
```### Set ID via Header
```sh
curl -I -H 'X-Request-ID:4ce4089d-e01e-4c7f-b35c-2ca383c7abf5' localhost:8080
# HTTP/1.1 200 OK
# X-Request-ID: 4ce4089d-e01e-4c7f-b35c-2ca383c7abf5
```--------------------------------------------------------------------------------
## Test
```sh
crystal spec
```--------------------------------------------------------------------------------
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b feature/`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin feature/`)
5. Create a new Pull Request--------------------------------------------------------------------------------
## Contributors
- [SuperPaintman](https://github.com/SuperPaintman) SuperPaintman - creator, maintainer
--------------------------------------------------------------------------------
## API
[Docs][docs-url]--------------------------------------------------------------------------------
## Changelog
[Changelog][changelog-url]--------------------------------------------------------------------------------
## License
[MIT][license-url]
[license-url]: LICENSE
[changelog-url]: CHANGELOG.md
[docs-url]: https://superpaintman.github.io/request-id/
[travis-image]: https://img.shields.io/travis/SuperPaintman/request-id/master.svg?label=linux
[travis-url]: https://travis-ci.org/SuperPaintman/request-id
[shards-image]: https://img.shields.io/github/tag/superpaintman/request-id.svg?label=shards
[shards-url]: https://github.com/superpaintman/request-id