2024-09-23 01:45:32 +00:00
# Mock HTTP Request

[](https://dart.dev/null-safety)
[](https://gitter.im/angel_dart/discussion)
[](https://github.com/dart-backend/angel/tree/master/packages/mock_request/LICENSE)
**Forked from `mock_request` to support NNBD**
Manufacture dart:io HttpRequests, HttpResponses, HttpHeaders, etc. This makes it possible to test server-side Dart applications without having to ever bind to a port.
2024-10-27 22:17:26 +00:00
This package was originally designed to make testing [Protevus ](https://protevus.com/ ) applications smoother, but works with any Dart-based server.
2024-09-23 01:45:32 +00:00
## Usage
```dart
var rq = MockHttpRequest('GET', Uri.parse('/foo'));
await rq.close();
await app.handleRequest(rq); // Run within your server-side application
var rs = rq.response;
expect(rs.statusCode, equals(200));
expect(await rs.transform(UTF8.decoder).join(),
equals(JSON.encode('Hello, world!')));
```
More examples can be found in the included test cases.