2021-06-24 11:59:11 +00:00
# Mock HTTP Request
2024-10-13 01:45:27 +00:00
![Pub Version (including pre-releases) ](https://img.shields.io/pub/v/protevus_mock_request?include_prereleases )
2021-05-14 08:06:16 +00:00
[![Null Safety ](https://img.shields.io/badge/null-safety-brightgreen )](https://dart.dev/null-safety)
2024-07-07 15:02:49 +00:00
[![Discord ](https://img.shields.io/discord/1060322353214660698 )](https://discord.gg/3X6bxTUdCM)
2024-10-12 10:35:14 +00:00
[![License ](https://img.shields.io/github/license/dart-backend/protevus )](https://github.com/dart-backend/protevus/tree/master/packages/mock_request/LICENSE)
2021-03-18 23:10:19 +00:00
2021-06-24 11:59:11 +00:00
**Forked from `mock_request` to support NNBD**
2023-05-21 00:53:53 +00:00
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.
2021-03-18 23:10:19 +00:00
2024-10-12 10:41:18 +00:00
This package was originally designed to make testing [Protevus ](https://protevus-framework.web.app/ ) applications smoother, but works with any Dart-based server.
2021-06-24 11:59:11 +00:00
## Usage
2021-03-18 23:10:19 +00:00
```dart
2021-05-14 08:06:16 +00:00
var rq = MockHttpRequest('GET', Uri.parse('/foo'));
2021-03-18 23:10:19 +00:00
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!')));
```
2021-06-24 11:59:11 +00:00
More examples can be found in the included test cases.