{"id":13483272,"url":"https://github.com/jwoertink/kave","last_synced_at":"2025-05-12T20:44:34.848Z","repository":{"id":66471622,"uuid":"72877515","full_name":"jwoertink/kave","owner":"jwoertink","description":"Kemal API Version Extension","archived":false,"fork":false,"pushed_at":"2019-10-27T17:56:46.000Z","size":54,"stargazers_count":29,"open_issues_count":4,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T09:11:26.743Z","etag":null,"topics":["api","crystal","kemal"],"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/jwoertink.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}},"created_at":"2016-11-04T19:08:22.000Z","updated_at":"2024-03-15T13:14:03.000Z","dependencies_parsed_at":"2024-03-03T08:43:53.039Z","dependency_job_id":null,"html_url":"https://github.com/jwoertink/kave","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwoertink%2Fkave","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwoertink%2Fkave/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwoertink%2Fkave/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwoertink%2Fkave/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwoertink","download_url":"https://codeload.github.com/jwoertink/kave/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246574865,"owners_count":20799225,"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":["api","crystal","kemal"],"created_at":"2024-07-31T17:01:09.573Z","updated_at":"2025-04-01T10:31:51.395Z","avatar_url":"https://github.com/jwoertink.png","language":"Crystal","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"# Kave (Kemal API Version Extension) [![Build Status](https://travis-ci.com/jwoertink/kave.svg?branch=master)](https://travis-ci.com/jwoertink/kave)\n\nThis shards makes it easier to version your [Kemal](http://kemalcr.com/) API\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  kave:\n    github: jwoertink/kave\n```\n\n\n## Usage\n\n```crystal\nrequire \"kemal\"\nrequire \"kave\"\n\nKave.configure do |c|\n  # These are default config options\n  # c.format = :json                # see Formats below\n  # c.auth_strategy = nil           # see Auth Strategy below\n  # c.token_model = Kave::AuthToken # see Auth Strategy below\n  # c.version_strategy = :header    # see Version Strategy below\nend\n\npublic do\n  get \"/\" do |env|\n    \"This is a public route\"\n  end\nend\n\napi(\"v1\") do\n  get \"/\" do |env|\n    \"This is a private route only accessed through the version 1 API\"\n  end\n\n  before_post \"/check\" do |env|\n    \"This is called before POST /v1/check\"\n  end\n  post \"/check\" do |env|\n    \"something here\"\n  end\nend\n\napi(\"v2\") do\n  get \"/\" do |env|\n    \"This is a private route only accessed through the version 2 API\"\n  end\nend\n```\n\n## Configuration Options\n\n### Formats\nThe formats are how your data will be returned. By default, Kave will assume you're building a JSON API.\nKave will automatically set your response `Content-Type` to match the type of API you're building. \n\nFor now, you must handle the data conversion yourself, but eventually Kave will take care of that for you. \n\n```crystal\n# assumes format is :json\napi(\"v1\") do\n  get \"/users/:id\" do |env|\n    {\"id\" =\u003e env.params.url[\"id\"], \"name\" =\u003e \"jeremy\"}.to_json\n  end\nend\n```\n\nYou would make a call to this route by `http://localhost:3000/v1/users/1`\n\nAdditional options later will be `:xml`, `:msgpack`, `:plain`\n\n### Auth Strategy\nIf your API isn't public, then you'll probably want to add some sort of API key. By default, Kave sets the `auth_strategy` to nil, but you can use a Bearer token authorization. To use this, set the `auth_strategy` to `:bearer`, and create a class that inherits from `Kave::AuthToken`. Set the `token_model` to your custom class, and make sure that class implements the class method `locate`.\n\n```crystal\nclass MyTokenModel \u003c Kave::AuthToken\n  def self.locate(token : String)\n    token == \"abc123\"\n  end\nend\n\nKave.configure do |c|\n  c.auth_strategy = :bearer\n  c.token_model = MyTokenModel\nend\n\napi(\"v1\") do\n  get \"/users/:id\" do |env|\n    {\"id\" =\u003e env.params.url[\"id\"], \"name\" =\u003e \"jeremy\"}.to_json\n  end\nend\n```\n\nTo access this route:\n```text\n$ curl -H \"Authorization: Bearer abc123\" \"http://localhost:3000/v1/users/1\"\n```\n\n### Version Strategy\n\nBy default, Kave will generate paths for your API by prepending the version to your route like `/v1/whatever`. This option gives you the ability to specify your routes like `/whatever` and control the version using a header. Later there may be an option like `:subdomain` to do `v1.whatever.com/whatever`.\n\n```crystal\nKave.configure do |c|\n  c.version_strategy = :header\nend\n\napi(\"v1\") do\n  get \"/users\" do |env|\n    [{\"id\" =\u003e 1, \"name\" =\u003e \"Jeremy\"}].to_json\n  end\nend\n```\n\nTo access this route:\n```text\n$ curl -H \"Accept: application/vnd.api.v1+json\" \"http://localhost:3000/users\"\n```\n\n**NOTE** In a previous version of Kave you were able to change this halfway through. I realized after lots of trail and error that this was going to cause a huge mess. You can't conditionally add middleware. It's either there, or it's not. I may add that back in later if I can come up with some clever way, but until people start asking for that, it's out for now.\n\n\n## Development\n\nThis is going to be a work in progress for a while. If you have a better idea for how something should be implemented, please open an issue, or submit a PR.\n\n## Contributing\n\n1. Fork it ( https://github.com/jwoertink/kave/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Make sure all specs pass\n5. Push to the branch (git push origin my-new-feature)\n6. Create a new Pull Request\n\n## Contributors\n\n- [jwoertink(https://github.com/jwoertink) Jeremy Woertink - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwoertink%2Fkave","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwoertink%2Fkave","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwoertink%2Fkave/lists"}