{"id":26127767,"url":"https://github.com/kwabenberko/net_mock","last_synced_at":"2026-05-06T04:07:47.523Z","repository":{"id":253805744,"uuid":"833109433","full_name":"KwabenBerko/net_mock","owner":"KwabenBerko","description":"A Dart package designed to simplify HTTP request mocking in your tests","archived":false,"fork":false,"pushed_at":"2024-08-28T01:30:06.000Z","size":36,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-26T15:12:37.137Z","etag":null,"topics":["dart","flutter","http","mock-client"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/net_mock","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KwabenBerko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-24T11:22:27.000Z","updated_at":"2025-09-30T06:40:31.000Z","dependencies_parsed_at":"2025-03-12T04:00:11.596Z","dependency_job_id":null,"html_url":"https://github.com/KwabenBerko/net_mock","commit_stats":null,"previous_names":["kwabenberko/net_mock"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KwabenBerko/net_mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KwabenBerko%2Fnet_mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KwabenBerko%2Fnet_mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KwabenBerko%2Fnet_mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KwabenBerko%2Fnet_mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KwabenBerko","download_url":"https://codeload.github.com/KwabenBerko/net_mock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KwabenBerko%2Fnet_mock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32677961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-06T02:33:58.958Z","status":"ssl_error","status_checked_at":"2026-05-06T02:33:39.611Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","http","mock-client"],"created_at":"2025-03-10T18:37:33.923Z","updated_at":"2026-05-06T04:07:47.497Z","avatar_url":"https://github.com/KwabenBerko.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# net_mock\n\n`net_mock` is a Dart package that streamlines the process of mocking HTTP requests in your tests.\nInspired by [NetMock](https://github.com/DenisBronx/NetMock), it extends the `http.MockClient`\npackage by adding a layer of syntactic sugar. This makes it even more straightforward to define and\nmanage expected requests and responses, allowing you to focus on writing clear and concise tests.\n\n## Features\n\n1. Mock HTTP requests and responses for all HTTP methods.\n2. Simplified API for setting up mocks.\n\n## Getting started\n\n### Prerequisites\n\nTo use `net_mock`, ensure you have the following:\n\n1. Dart SDK `2.12.0` or later.\n2. A Flutter or Dart project.\n\n### Installation\n\nAdd `net_mock` to your pubspec.yaml:\n\n```yaml\ndependencies:\n  net_mock: ^1.0.7\n```\n\nThen, run `flutter pub get` to install the package.\n\n## Usage\n\n### Basic Setup\n\nHere's a basic example of how to use `net_mock` to mock a GET request in a test:\n\n```dart\nvoid main() {\n  late NetMock netMock;\n  late NumberRepository sut;\n\n  setUp(() {\n    netMock = NetMock();\n    sut = NumberRepository(client: netMock.client);\n  });\n\n  test(\n    \"should return random fact for number\",\n        () async {\n      netMock.addMock(\n        request: NetMockRequest(\n          url: Uri.parse(\"http://numbersapi.com/42\"),\n          method: Method.get,\n        ),\n        response: NetMockResponse(\n          code: 200,\n          body: \"42 is the number of US gallons in a barrel of oil.\",\n        ),\n      );\n\n      final result = await sut.getFactForNumber(number: 42);\n\n      expect(\n        result,\n        equals(\"42 is the number of US gallons in a barrel of oil.\"),\n      );\n    },\n  );\n}\n\nclass NumberRepository {\n  final Client client;\n\n  NumberRepository({required this.client});\n\n  Future\u003cString\u003e getFactForNumber({required int number}) async {\n    final response = await client.get(\n      Uri.parse(\"http://numbersapi.com/$number\"),\n      headers: {\n        HttpHeaders.contentTypeHeader: \"application/json; charset=utf-8\"\n      },\n    );\n    return response.body;\n  }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwabenberko%2Fnet_mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkwabenberko%2Fnet_mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkwabenberko%2Fnet_mock/lists"}