{"id":15176416,"url":"https://github.com/zotonic/cowmachine","last_synced_at":"2025-05-08T21:09:29.841Z","repository":{"id":37733062,"uuid":"63611545","full_name":"zotonic/cowmachine","owner":"zotonic","description":"Webmachine for Zotonic and Cowboy","archived":false,"fork":false,"pushed_at":"2024-11-14T07:41:16.000Z","size":4543,"stargazers_count":13,"open_issues_count":2,"forks_count":5,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-12-19T04:07:06.504Z","etag":null,"topics":["cowboy","erlang","erlang-library","http-server","webmachine","zotonic"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zotonic.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-07-18T14:50:00.000Z","updated_at":"2024-11-14T07:40:06.000Z","dependencies_parsed_at":"2024-03-20T12:56:07.722Z","dependency_job_id":null,"html_url":"https://github.com/zotonic/cowmachine","commit_stats":{"total_commits":119,"total_committers":5,"mean_commits":23.8,"dds":"0.26050420168067223","last_synced_commit":"855fccbbf9d6041abaa0f76bda295d4f9554f8fe"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fcowmachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fcowmachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fcowmachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zotonic%2Fcowmachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zotonic","download_url":"https://codeload.github.com/zotonic/cowmachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231481049,"owners_count":18383151,"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":["cowboy","erlang","erlang-library","http-server","webmachine","zotonic"],"created_at":"2024-09-27T13:04:07.655Z","updated_at":"2024-12-27T12:07:55.439Z","avatar_url":"https://github.com/zotonic.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Test](https://github.com/zotonic/cowmachine/actions/workflows/test.yml/badge.svg)](https://github.com/zotonic/cowmachine/actions/workflows/test.yml)\n[![Hex.pm version][hexpm version]][hexpm]\n[![Hex.pm Downloads][hexpm downloads]][hexpm]\n[![Hex.pm Documentation][hexdocs documentation]][hexdocs]\n[![Erlang Versions][erlang version badge]][gh]\n[![License][license]](https://www.apache.org/licenses/LICENSE-2.0)\n\n\n# Cowmachine\n\nWebmachine for Zotonic and Cowboy\n\nThis is an adaptation of https://github.com/webmachine/webmachine for the Cowboy web server.\n\nCowmachine is a request handler for Cowboy.\n\nMain differences with Basho’s Webmachine are:\n\n * Use cowboy instead of mochiweb for the http server\n * Separate dispatching\n * Simplified callbacks\n * Single `process/4` callback for all http methods\n * Caching of some callbacks (like `modified`)\n * More streaming options for returned data\n * Better support for range requests\n\n## Installation\n\nCowmachine is at Hex, in your `rebar.config` file use:\n\n```erlang\n{deps, [\n    cowmachine\n]}.\n```\n\nYou can also use the direct Git url and use the development version:\n\n```erlang\n{deps, [\n    {cowmachine, {git, \"https://github.com/zotonic/cowmachine.git\", {branch, \"master\"}}}\n]}.\n```\n\n## Calling Cowmachine\n\nCowmachine can be called from your Cowboy middleware:\n\n```erlang\n-spec execute(Req, Env) -\u003e {ok, Req, Env} | {stop, Req}\n    when Req::cowboy_req:req(), Env::cowboy_middleware:env().\nexecute(Req, Env) -\u003e\n    % Replace below with your own controller module and optionally wrap\n    % the request in your own request-context record or map.\n    EnvController = Env#{\n        cowmachine_controller =\u003e mycontroller\n    },\n    RequestContext = cowmachine_req:init_context(Req, EnvController, #{}),\n    % Set options for the cowmachine\n    Options = #{\n        on_request =\u003e\n            fun(Ctx) -\u003e\n                % Perform anything after initialization of your request\n                % Examples are checking special cookies, changing headers, etc.\n                Ctx\n            end,\n        on_welformed =\u003e\n            fun(Ctx) -\u003e\n                % Perform anything after well-formedness check of your request\n                % Examples are parsing the query args, or authentication\n                Ctx\n            end,\n        on_handled =\u003e\n            fun(Ctx) -\u003e\n                % Perform anything after processing, before sending the result.\n                Ctx\n            end\n    },\n    % Handle the request, returns updated Req and Env for next Cowboy middleware\n    cowmachine:request(RequestContext, Options).\n```\n\nOr just use the default Cowmachine middleware:\n\n```erlang\n    #{\n        middlewares =\u003e [\n            % ... add your dispatcher middlware\n            cowmachine\n        ],\n        request_timeout =\u003e 60000,\n        env =\u003e #{\n            % If no dispatcher, default to `mycontroller` as the cowmachine\n            % controller.\n            cowmachine_controller =\u003e mycontroller\n        }\n    }.\n```\n\n## Dispatching\n\nYou can use the [Zotonic Dispatch Compiler](https://github.com/zotonic/dispatch_compiler) to match your controller paths against the request.\n\n\n## Controller\n\nThe controller provides the callbacks to handle the request.\n\nThe controller is an Erlang module implementing callback functions, only functions that return some non-default value need to be implemented.\n\nFor the controller callbacks and more documentation, check the [wiki pages](https://github.com/zotonic/cowmachine/wiki).\n\n## Documentation generation\n\n### Edoc\n\n#### Generate public API\n`rebar3 edoc`\n\n#### Generate private API\n`rebar3 as edoc_private edoc`\n\n### ExDoc\n\n`rebar3 ex_doc --logo doc/img/logo.png --output edoc -f html`\n\n\u003c!-- Badges --\u003e\n[hexpm]: https://hex.pm/packages/cowmachine\n[hexpm version]: https://img.shields.io/hexpm/v/cowmachine.svg?style=flat-curcle \"Hex version\"\n[hexpm downloads]: https://img.shields.io/hexpm/dt/cowmachine.svg?style=flat-curcle\n[hexdocs documentation]: https://img.shields.io/badge/hex-docs-purple.svg?style=flat-curcle\n[hexdocs]: https://hexdocs.pm/cowmachine\n[gh]: https://github.com/zotonic/cowmachine/actions/workflows/test.yaml\n[gh badge]: https://img.shields.io/github/workflow/status/zotonic/cowmachine/Test?style=flat-curcle\n[erlang version badge]: https://img.shields.io/badge/Supported%20Erlang%2FOTP-22.0%20to%2024.0-blue.svg?style=flat-curcle\n[license]: https://img.shields.io/badge/License-Apache_2.0-blue.svg?logo=apache\u0026logoColor=red \"Apache 2.0\"\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzotonic%2Fcowmachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzotonic%2Fcowmachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzotonic%2Fcowmachine/lists"}