{"id":13508078,"url":"https://github.com/henrik/plug_and_play","last_synced_at":"2026-02-18T23:32:18.707Z","repository":{"id":57534306,"uuid":"83123309","full_name":"henrik/plug_and_play","owner":"henrik","description":"Set up an Elixir Plug application with less boilerplate.","archived":false,"fork":false,"pushed_at":"2017-03-05T07:19:22.000Z","size":33,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-21T15:36:12.862Z","etag":null,"topics":["plug"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/henrik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-25T10:10:13.000Z","updated_at":"2023-09-01T10:44:24.000Z","dependencies_parsed_at":"2022-09-26T18:21:31.667Z","dependency_job_id":null,"html_url":"https://github.com/henrik/plug_and_play","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/henrik/plug_and_play","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik%2Fplug_and_play","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik%2Fplug_and_play/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik%2Fplug_and_play/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik%2Fplug_and_play/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/henrik","download_url":"https://codeload.github.com/henrik/plug_and_play/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/henrik%2Fplug_and_play/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29598237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T22:25:43.180Z","status":"ssl_error","status_checked_at":"2026-02-18T22:25:42.766Z","response_time":162,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["plug"],"created_at":"2024-08-01T02:00:47.580Z","updated_at":"2026-02-18T23:32:17.689Z","avatar_url":"https://github.com/henrik.png","language":"Elixir","funding_links":[],"categories":["Framework Components"],"sub_categories":[],"readme":"# PlugAndPlay 🔌►\n\n[![Build Status](https://secure.travis-ci.org/henrik/plug_and_play.svg?branch=master \"Build Status\")](https://travis-ci.org/henrik/plug_and_play) [![Elixir Forum](https://img.shields.io/badge/discuss-Elixir%20Forum-b36ccc.svg)](https://elixirforum.com/t/plugandplay-set-up-plug-apps-with-less-boilerplate/3851)\n\nSet up a `Plug` application with less boilerplate.\n\n`PlugAndPlay` is not a web framework – it's a small scaffold. You use `Plug` as you would normally, only *sooner*.\n\nLater, if you need more control, you can easily replace `PlugAndPlay` piece by piece or wholesale.\n\n\n## Setting up a Plug app, the easy way\n\nGenerate a new project with `--sup`, e.g.\n\n    mix new hello_world --sup\n\nOpen `mix.exs` and add `plug_and_play` to your list of dependencies:\n\n```elixir\ndef deps do\n  [\n    {:plug_and_play, \"~\u003e 0.7.0\"},\n  ]\nend\n```\n\n*(This makes `PlugAndPlay` conveniences available and saves you from manually adding Plug and the [Cowboy](https://github.com/ninenines/cowboy) web server to the deps list.)*\n\nMake your root module (e.g. `lib/hello_world.ex`) look something like:\n\n```elixir\ndefmodule HelloWorld do\n  defmodule Router do\n    use PlugAndPlay.Router\n\n    get \"/\" do\n      send_resp conn, 200, \"Hello world!\"\n    end\n\n    match _ do\n      send_resp conn, 404, \"404!\"\n    end\n  end\nend\n```\n\n*(This saves you from manually including some `Plug.Router` boilerplate.)*\n\nMake your application module (e.g. `lib/hello_world/application.ex`) look something like:\n\n```elixir\ndefmodule HelloWorld.Application do\n  use PlugAndPlay.Application, router: HelloWorld.Router\nend\n```\n\n*(This saves you from manually setting up a Supervisor to run your app in the Cowboy web server on the right port.)*\n\nNow you should be able to start the app in a terminal with:\n\n    mix deps.get\n    mix server\n\n*(This saves you from typing `mix run --no-halt`.)*\n\nIt outputs the URL at which the server runs - usually \u003chttp://0.0.0.0:8080\u003e. Go there and marvel!\n\n\n## Custom port number\n\nThe default port is 8080.\n\nIf the environment variable `PORT` is set, that port number will be used. This is the convention on e.g. [Heroku](https://heroku.com) and with [Dokku](http://dokku.viewdocs.io/dokku/), meaning things will Just Work™ if you deploy there.\n\nOr you can assign a port explicitly, e.g. from application config.\n\nAssuming you have config like this in `config/config.exs`:\n\n```elixir\nconfig :hello_world, port: 1234\n```\n\nYou could do this in `lib/hello_world/application.ex`:\n\n\n```elixir\ndefmodule HelloWorld.Application do\n  use PlugAndPlay.Application,\n    router: HelloWorld.Router,\n    port: Application.get_env(:hello_world, :port)\nend\n```\n\nIf you set up your own supervision tree, you can also [specify the port there](#custom-supervision).\n\n\n## Custom plug pipeline\n\nIf you need additional plugs, skip `use PlugAndPlay.Router` and simply write out the code instead:\n\n```elixir\nuse Plug.Router\n\nplug :match\nplug :my_custom_plug\nplug :dispatch\n```\n\nYou can still use the rest of the `PlugAndPlay` conveniences, of course, even if you skip `PlugAndPlay.Router`.\n\n\n## Custom supervision\n\nBy default, `PlugAndPlay` defines a supervision tree for you so you don't have to. If that's all you need, ignore this section.\n\nIf you want more control, you can define your own supervision tree with `PlugAndPlay.Supervisor` as one of its children.\n\nMake your main application (e.g. `lib/hello_world/application.ex`) look something like:\n\n```elixir\ndefmodule HelloWorld.Application do\n  use Application\n\n  def start(_type, _args) do\n    children = [\n      PlugAndPlay.Supervisor.child_spec(HelloWorld.Router),\n    ]\n\n    Supervisor.start_link(children, strategy: :one_for_one)\n  end\nend\n```\n\nYou can specify the desired port as a second argument to `child_spec`.\n\nYou can specify multiple instances as long as they have different routers and ports:\n\n```elixir\nchildren = [\n  PlugAndPlay.Supervisor.child_spec(HelloWorld.RouterOne, 1111),\n  PlugAndPlay.Supervisor.child_spec(HelloWorld.RouterTwo, 2222),\n]\n```\n\n\n## Credits and license\n\nBy [Henrik Nyh](https://henrik.nyh.se) 2017-02-25 under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrik%2Fplug_and_play","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenrik%2Fplug_and_play","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenrik%2Fplug_and_play/lists"}