Trot.Router

Source

Summary

delete(path, options \\ [], list3)
do_redirect(path, conn)

Redirect the request to another location

get(path, options \\ [], list3)
make_response(conn, conn)

Encodes HTTP responses as appropriate and passes them to Plug.Conn

options(path, options \\ [], list3)
patch(path, options \\ [], list3)
post(path, options \\ [], list3)
put(path, options \\ [], list3)
redirect(from, to)
static(at, from)

Functions

do_redirect(path, conn)

Redirect the request to another location.

Source
make_response(conn, conn)

Encodes HTTP responses as appropriate and passes them to Plug.Conn.

Examples

# Sets status code to 200 with an empty body
get "/" do
  200
end

# Returns an empty body with a status code of 404
get "/bad" do
  :bad_request
end

# Sets the status code to 200 with a text body
get "/text" do
  "Thank you for your question."
end

# Sets the status code to 201 with a text body
get "/text/body" do
  {201, "Thank you for your question."}
end

# Sets status code to 200 with a JSON-encoded body
get "/json" do
  %{"hyper" => "social"}
end

# Sets the status code to 201 with a JSON-encoded body
get "/json/code" do
  {201, %{"hyper" => "social"}}
end

# Set the response manually as when using Plug directly
get "/conn" do
  send_resp(conn, 200, "optimal tip-to-tip efficiency")
end

# Pattern match part of the path into a variable
get "/presenter/:name" do
  "The presenter is #{name}"
end

# Redirect the incoming request
get "/redirect" do
  {:redirect, "/text/body"}
end
Source

Macros

delete(path, options \\ [], list3)
Source
get(path, options \\ [], list3)
Source
options(path, options \\ [], list3)
Source
patch(path, options \\ [], list3)
Source
post(path, options \\ [], list3)
Source
put(path, options \\ [], list3)
Source
redirect(from, to)
Source
static(at, from)
Source