Skip to content

Commit

Permalink
Add examples to the README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenwindler committed Jul 25, 2018
1 parent b306c09 commit 6719970
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Http Helper

A tiny collection of helper functions for your everyday work with http requests and responses.
A collection of helper functions for your everyday work with http requests and responses.

Supports
* PSR-7 (`Psr\Http\Message\RequestInterface`, `Psr\Http\Message\ResponseInterface`)
* Symfony HttpFoundation (`Symfony\Component\HttpFoundation\Request`, `Symfony\Component\HttpFoundation\Response`)

The main idea of these functions was to provide quick access to the http information during development (e.g. via the debugger console), that's why the functions are not namespaced. *It's not meant to be used in your actual code*!
The main idea of these functions was to provide quick access to the http information during development (e.g. via the debugger console), that's why the functions are not namespaced. *It's not meant to be used in your actual code*! Srsly, it's not.

# Example

Here are some http-helper functions in action:

![Basic usage](http://media.carstenwindler.de/packages/http-helper/http-helper-example-basic-usage.gif "Basic usage of http-helper")

# Installation

`composer require-dev carstenwindler/http-helper`

(I suggest to use these functions as `require-dev` only, however of course they can also be used as require).
(I suggest to only add these functions as `require-dev`).

The functions are registered using the composer autoload feature, so there is nothing more for you to do.

Expand All @@ -32,6 +38,8 @@ Just like _request_to_string()_, but the request string will be stored in a file

This way you can e.g. easily execute the request using PhpStorms cool [Editor-based Rest Client](https://blog.jetbrains.com/phpstorm/2017/09/editor-based-rest-client/).

If the file already exists and is not empty, the request will be appended.

### request_to_curl()

Returns the request object as cURL command, so it can be used e.g. on console or import it in Postman easily.
Expand All @@ -48,13 +56,23 @@ Serializes the response object in plain HTTP format according to [RFC 7230](http

Just like `response_to_string()`, but the response string will be stored in a file called `response.http` in your DOCUMENT_ROOT.

# File usage

The following example shows you how to store requests and responses in files easily.

![Advanced usage example](http://media.carstenwindler.de/packages/http-helper/http-helper-example-file-usage.gif "Basic usage of http-helper")

But why would you do that? Here, PhpStorm comes into play. It now comes equipped with the cool [Editor-based Rest Client](https://blog.jetbrains.com/phpstorm/2017/09/editor-based-rest-client/) (think of it like a very simple Postman without all the fancy gui).

*http-helper* uses the suffix `.http`, which is recognised by PhpStorm, so you will immediately have the possibility to modify and rerun the request in that file. I quite like the idea, since you could add it to your code base, so your fellow devs would have immediate access.

# Credits

The serialization of the PSR-7 requests and responses are done using [Zend Diactoros](https://github.com/zendframework/zend-diactoros). Weird name, great library!

For Symfony, the build-in serializers are used.
For Symfony, the build-in serializers are used. Nice.

# Todo

* setup TravisCI
* make storage path of `*_to_file()` configurable
* make storage path of `*_to_file()` configurable

0 comments on commit 6719970

Please sign in to comment.