0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00
cowboy/examples
Loïc Hoguin b370442a63 Initial commit with connection/streams
Breaking changes with previous commit. This is a very large change,
and I am giving up on making a single commit that fixes everything.
More commits will follow slowly adding back features, introducing
new tests and fixing the documentation.

This change contains most of the work toward unifying the interface
for handling both HTTP/1.1 and HTTP/2. HTTP/1.1 connections are now
no longer 1 process per connection; instead by default 1 process per
request is also created. This has a number of pros and cons.

Because it has cons, we also allow users to use a lower-level API
that acts on "streams" (requests/responses) directly at the connection
process-level. If performance is a concern, one can always write a
stream handler. The performance in this case will be even greater
than with Cowboy 1, although all the special handlers are unavailable.

When switching to Websocket, after the handler returns from init/2,
Cowboy stops the stream and the Websocket protocol takes over the
connection process. Websocket then calls websocket_init/2 for any
additional initialization such as timers, because the process is
different in init/2 and websocket_*/* functions. This however would
allow us to use websocket_init/2 for sending messages on connect,
instead of sending ourselves a message and be subject to races.
Note that websocket_init/2 is optional.

This is all a big change and while most of the tests pass, some
functionality currently doesn't. SPDY is broken and will be removed
soon in favor of HTTP/2. Automatic compression is currently disabled.
The cowboy_req interface probably still have a few functions that
need to be updated. The docs and examples do not refer the current
functionality anymore.

Everything will be fixed over time. Feedback is more than welcome.
Open a ticket!
2016-03-05 20:20:42 +01:00
..
chunked_hello_world Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
compress_response Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
cookie Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
echo_get Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
echo_post Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
error_hook Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
eventsource Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
hello_world Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
markdown_middleware Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
rest_basic_auth Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
rest_hello_world Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
rest_pastebin Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
rest_stream_response Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
ssl_hello_world Initial commit with connection/streams 2016-03-05 20:20:42 +01:00
static_world Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
upload Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
web_server Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
websocket Simplify specifying the Cowboy version in examples 2016-01-14 22:58:22 +01:00
README.asciidoc Convert the example index README to AsciiDoc 2016-01-14 20:09:01 +01:00

= Cowboy examples

* link:chunked_hello_world[]:
  demonstrate chunked data transfer with two one-second delays

* link:compress_response[]:
  send a response body compressed if the client supports it

* link:cookie[]:
  set cookies from server and client side

* link:echo_get[]:
  parse and echo a GET query string

* link:echo_post[]:
  parse and echo a POST parameter

* link:error_hook[]:
  provide custom error pages

* link:eventsource[]:
  eventsource emitter and consumer

* link:hello_world[]:
  simplest example application

* link:markdown_middleware[]:
  static file handler with markdown preprocessor

* link:rest_basic_auth[]:
  basic HTTP authorization with REST

* link:rest_hello_world[]:
  return the data type that matches the request type (ex: html, text, json)

* link:rest_pastebin[]:
  create text objects and return the data type that matches the request type (html, text)

* link:rest_stream_response[]:
  stream results from a data store

* link:ssl_hello_world[]:
  simplest SSL application

* link:static_world[]:
  static file handler

* link:upload[]:
  multipart/form-data upload

* link:web_server[]:
  serve files with lists directory entries

* link:websocket[]:
  websocket example

== Other languages

* https://github.com/joshrotenberg/elixir_cowboy_examples[Elixir]
* https://github.com/quasiquoting/lfe-cowboy-examples[LFE]