From 9b8d879e0f8e8080d8ede89b1097cbb01854cc19 Mon Sep 17 00:00:00 2001 From: Jacob Mather Date: Thu, 4 Oct 2012 12:19:25 -0400 Subject: [PATCH] Added readme --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d05fd31 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# Accept Header Service Provider + +This serivce provider enables you to easily filter routes based on accept headers. + +To use it, simply do the following: + + register(new AcceptHeaderServiceProvider()); + + $app->get('/test', function($accept_header) { + if ($accept_header == 'application/ven.test.v1+json') + $cont = json_encode(array('content' => 'hello')); + else + $cont = 'hello'; + + return new Response($cont, 200, array('Content-Type' => $accept_header)); + })->accept(array('application/ven.test.v1+json', 'application/ven.test.v1+xml')); + + + $app->get('/test', function($accept_header) { + if ($accept_header == 'application/ven.test.v2+json') + $cont = json_encode(array('content' => 'hiya')); + else + $cont = 'hiya'; + + return new Response($cont, 200, array('Content-Type' => $accept_header)); + })->accept(array('application/ven.test.v2+json', 'application/ven.test.v2+xml')); + + +Now a request with accept headers including `application/ven.test.v1+json` and `application/ven.test.v1+xml` +will be handled by the first route, and requests with accept headers including `application/ven.test.v2+json` and +`application/ven.test.v2+xml` will be routed to the second.