{"id":16032736,"url":"https://github.com/threez/context.cr","last_synced_at":"2026-07-03T14:05:10.094Z","repository":{"id":153241372,"uuid":"628612671","full_name":"threez/context.cr","owner":"threez","description":"The missing context shard for crystal","archived":false,"fork":false,"pushed_at":"2023-04-16T14:04:28.000Z","size":5,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-07T08:12:34.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/threez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-16T13:53:37.000Z","updated_at":"2023-05-11T14:19:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"1548643f-a04d-47e7-82fd-61d046755c0a","html_url":"https://github.com/threez/context.cr","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fcontext.cr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fcontext.cr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fcontext.cr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/threez%2Fcontext.cr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/threez","download_url":"https://codeload.github.com/threez/context.cr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246644097,"owners_count":20810687,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T21:40:27.629Z","updated_at":"2026-07-03T14:05:10.036Z","avatar_url":"https://github.com/threez.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# context [![.github/workflows/ci.yml](https://github.com/threez/context.cr/actions/workflows/ci.yml/badge.svg)](https://github.com/threez/context.cr/actions/workflows/ci.yml) [![https://threez.github.io/context.cr/](https://badgen.net/badge/api/documentation/green)](https://threez.github.io/context.cr/)\n\nComing from languages like golang you might miss the equivalent of a context providing\nlibrary to help support your cross functional requirements. This library adds the \ncontext right to the current `Fiber`. It handles immutable context variables using `Fiber.current.with_values` that can be accessed by `Fiber.current[]`.\n\nThe heavy lifting is done by the stdlib `Log::Metadata` implementation.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     context:\n       github: threez/context.cr\n   ```\n\n2. Run `shards install`\n\n## Usage\n\n\n\n```crystal\nrequire \"context\"\nrequire \"http/server\"\nrequire \"http/client\"\n\nclass AuthHandler\n  include HTTP::Handler\n\n  def call(context)\n    # take token from request and verify it\n    Fiber.current.with_values token: \"123\" do\n      call_next(context)\n    end\n  end\nend\n\n# lets assume that is a different internal micro service that wants to get the token...\nclient = HTTP::Client.new(URI.parse(\"https://example.com\"))\nclient.before_request do |context|\n  context.headers[\"Authorization\"] = \"Bearer #{Fiber.current[:token]}\"\nend\n\nserver = HTTP::Server.new([\n  AuthHandler.new,\n]) do |context|\n  context.response.content_type = \"text/plain\"\n  context.response.print \"Hello world, got #{context.request.path}!\"\n\n  client.get(\"/secret/data\")\nend\n\nputs \"Listening on http://127.0.0.1:8080\"\nserver.listen(8080)\n```\n\n## Resources\n\n* [Forum Discussion](https://forum.crystal-lang.org/t/how-do-you-manage-context/5572)\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/threez/context/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [threez](https://github.com/threez) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreez%2Fcontext.cr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthreez%2Fcontext.cr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthreez%2Fcontext.cr/lists"}