{"id":17681764,"url":"https://github.com/jgaskins/armature","last_synced_at":"2025-05-12T14:03:19.509Z","repository":{"id":143300785,"uuid":"335787525","full_name":"jgaskins/armature","owner":"jgaskins","description":"Roda-inspired HTTP framework for Crystal, providing routing, sessions, forms, etc","archived":false,"fork":false,"pushed_at":"2025-05-02T03:15:36.000Z","size":202,"stargazers_count":27,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-06T18:16:16.387Z","etag":null,"topics":["crystal","http","http-server","routing"],"latest_commit_sha":null,"homepage":"","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/jgaskins.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":"2021-02-03T23:54:35.000Z","updated_at":"2025-05-02T03:15:39.000Z","dependencies_parsed_at":"2024-02-17T08:26:12.005Z","dependency_job_id":"719149c8-9b60-445b-a461-2c72e837a091","html_url":"https://github.com/jgaskins/armature","commit_stats":{"total_commits":58,"total_committers":3,"mean_commits":"19.333333333333332","dds":0.1724137931034483,"last_synced_commit":"f68a1777699a6106ebafe2c957efbaa8c7cc3272"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Farmature","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Farmature/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Farmature/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jgaskins%2Farmature/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jgaskins","download_url":"https://codeload.github.com/jgaskins/armature/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253754090,"owners_count":21958838,"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":["crystal","http","http-server","routing"],"created_at":"2024-10-24T09:12:08.384Z","updated_at":"2025-05-12T14:03:19.453Z","avatar_url":"https://github.com/jgaskins.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Armature\n\nArmature is an HTTP routing framework for Crystal.\n\n## Installation\n\n1. Add the dependency to your `shard.yml`:\n\n   ```yaml\n   dependencies:\n     armature:\n       github: jgaskins/armature\n   ```\n\n2. Run `shards install`\n\n## Usage\n\nArmature has 2 primary components:\n\n- `Armature::Route`\n  - Provides a routing graph by allowing a top-level application to delegate to various child routes based on path segments\n  - Provides an [ECR](https://crystal-lang.org/api/1.0.0/ECR.html) rendering macro to render view templates at compile time. View templates are under the `views/` directory in the application root.\n  - Provides a missed-match handler (`r.miss`) so you can provide custom 404 handling in a way that's simple and discoverable\n- `Armature::Session`\n  - If you're using cookie-based authentication, you can use Armature sessions to persist session data between requests\n  - Currently the only supported session adapter is `Armature::Session::RedisStore`. The value stored in the cookie is the session id and the data stored in Redis will be the session data serialized into a JSON string.\n\n```crystal\nrequire \"armature\"\nrequire \"armature/redis_session\"\nrequire \"redis\"\n\nclass App\n  include HTTP::Handler\n  include Armature::Route\n\n  def call(context)\n    route context do |r, response, session|\n      # The `session` can be treated as a key/value object. All JSON-friendly\n      # types can be stored and retrieved. The stored session data is saved as\n      # JSON and parsed into a `JSON::Any`.\n      if current_user_id = session[\"user_id\"]?.try(\u0026.as_i?)\n        current_user = UserQuery.new.find_by_id(current_user_id)\n      end\n\n      # `render` macro provided by `Armature::Route` renders the given template\n      # inside the `views/` directory to the `response` object. This example\n      # renders `views/app_header.ecr`.\n      #\n      # Note: You can render as many templates as you need, allowing for nesting\n      # your UI via nested routes.\n      render \"app_header\"\n      \n      # Root path (all HTTP verbs)\n      r.root do\n        # Execute the given block only for GET requests\n        r.get { render \"homepage\" }\n\n        # Execute the given block only for POST requests\n        r.post do\n          # ...\n        end\n      end\n\n      # Delegate certain paths to other `Armature::Route`s with `on`\n      r.on \"products\" { Products.new.call(context) }\n\n      # Allow for authenticated-only routes\n      if current_user\n        r.on \"notifications\" { Notifications.new(current_user).call(context) }\n        r.on \"cart\" { Cart.new(current_user).call(context) }\n      end\n\n      # Execute a block if an endpoint has not been reached yet.\n      r.miss do\n        response.status = :not_found\n        render \"not_found\"\n      end\n\n      # Rendering the footer below main app content\n      render \"app_footer\"\n    end\n  end\nend\n\nhttp = HTTP::Server.new([\n  Armature::Session::RedisStore.new(\n    # the HTTP cookie name to store the session id in\n    key: \"app_session\",\n    # a client for the Redis instance to store session data in\n    redis: Redis::Client.from_env(\"REDIS_URL\"),\n  ),\n  App.new,\n])\nhttp.listen 8080\n```\n\nOther useful components are:\n\n- `Armature::Form::Helper`\n- `Armature::Cache`\n- `Armature::Component`\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/jgaskins/armature/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- [Jamie Gaskins](https://github.com/jgaskins) - creator and maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgaskins%2Farmature","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjgaskins%2Farmature","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjgaskins%2Farmature/lists"}