|
4 | 4 |
|
5 | 5 | [](https://travis-ci.org/fastify/light-my-request) [](http://standardjs.com/) |
6 | 6 |
|
7 | | -Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. |
8 | | -Does not use a socket connection so can be run against an inactive server (server not in listen mode). |
| 7 | +Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. |
| 8 | +Does not use a socket connection so can be run against an inactive server (server not in listen mode). |
9 | 9 |
|
10 | 10 | ## Example |
11 | 11 |
|
@@ -131,26 +131,6 @@ The declaration file exports types for the following parts of the API: |
131 | 131 | - `Request` - custom light-my-request `request` object interface. Extends Node.js `stream.Readable` type |
132 | 132 | - `Response` - custom light-my-request `response` object interface. Extends Node.js `http.ServerResponse` type |
133 | 133 |
|
134 | | -### Example with Express |
135 | | - |
136 | | -```javascript |
137 | | -const http = require('http') |
138 | | -const inject = require('light-my-request') |
139 | | - |
140 | | -const dispatch = function (req, res) { |
141 | | - const reply = 'Hello World' |
142 | | - res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length }) |
143 | | - res.end(reply) |
144 | | -} |
145 | | - |
146 | | -const server = http.createServer(dispatch) |
147 | | - |
148 | | -inject(dispatch, { method: 'get', url: '/', express: true }, (err, res) => { |
149 | | - console.log(res.payload) |
150 | | -}) |
151 | | -``` |
152 | | -Note the `express: true` in the above example. This flag makes sure that we still get the correct behaviour with express framework. |
153 | | - |
154 | 134 | ## API |
155 | 135 |
|
156 | 136 | #### `inject(dispatchFunc[, options, callback])` |
@@ -179,7 +159,6 @@ Injects a fake request into an HTTP server. |
179 | 159 | - `server` - Optional http server. It is used for binding the `dispatchFunc`. |
180 | 160 | - `autoStart` - Automatically start the request as soon as the method |
181 | 161 | is called. It is only valid when not passing a callback. Defaults to `true`. |
182 | | - - `express` - A boolean flag to enable working with express framework. By default express doesn't support request injection, this enforces. |
183 | 162 | - `callback` - the callback function using the signature `function (err, res)` where: |
184 | 163 | - `err` - error object |
185 | 164 | - `res` - a response object where: |
@@ -246,8 +225,8 @@ inject(dispatch) |
246 | 225 | Note: The application would not respond multiple times. If you try to invoking any method after the application has responded, the application would throw an error. |
247 | 226 |
|
248 | 227 | ## Acknowledgements |
249 | | -This project has been forked from [`hapi/shot`](https://github.com/hapijs/shot) because we wanted to support *Node ≥ v4* and not only *Node ≥ v8*. |
250 | | -All the credits before the commit [00a2a82](https://github.com/fastify/light-my-request/commit/00a2a82eb773b765003b6085788cc3564cd08326) goes to the `hapi/shot` project [contributors](https://github.com/hapijs/shot/graphs/contributors). |
| 228 | +This project has been forked from [`hapi/shot`](https://github.com/hapijs/shot) because we wanted to support *Node ≥ v4* and not only *Node ≥ v8*. |
| 229 | +All the credits before the commit [00a2a82](https://github.com/fastify/light-my-request/commit/00a2a82eb773b765003b6085788cc3564cd08326) goes to the `hapi/shot` project [contributors](https://github.com/hapijs/shot/graphs/contributors). |
251 | 230 | Since the commit [db8bced](https://github.com/fastify/light-my-request/commit/db8bced10b4367731688c8738621d42f39680efc) the project will be maintained by the Fastify team. |
252 | 231 |
|
253 | 232 | ## License |
|
0 commit comments