{"id":29215214,"url":"https://github.com/pronamic/wp-http","last_synced_at":"2025-07-03T00:08:33.434Z","repository":{"id":57045249,"uuid":"346015615","full_name":"pronamic/wp-http","owner":"pronamic","description":"WordPress HTTP library.","archived":false,"fork":false,"pushed_at":"2024-12-17T12:45:41.000Z","size":229,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-29T23:05:03.533Z","etag":null,"topics":["api","faking-responses","http","library","unit-testing","wordpress"],"latest_commit_sha":null,"homepage":"https://pronamic.github.io/wp-http/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pronamic.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":"2021-03-09T13:28:32.000Z","updated_at":"2024-12-17T12:45:44.000Z","dependencies_parsed_at":"2024-06-19T05:14:05.008Z","dependency_job_id":"d9268ee2-9f2c-410d-866e-800089853887","html_url":"https://github.com/pronamic/wp-http","commit_stats":{"total_commits":74,"total_committers":2,"mean_commits":37.0,"dds":"0.31081081081081086","last_synced_commit":"1f080f7ef4f134c3c4bbce023676e17eafa4e840"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/pronamic/wp-http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pronamic%2Fwp-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pronamic%2Fwp-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pronamic%2Fwp-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pronamic%2Fwp-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pronamic","download_url":"https://codeload.github.com/pronamic/wp-http/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pronamic%2Fwp-http/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263234961,"owners_count":23434921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["api","faking-responses","http","library","unit-testing","wordpress"],"created_at":"2025-07-03T00:08:26.274Z","updated_at":"2025-07-03T00:08:33.252Z","avatar_url":"https://github.com/pronamic.png","language":"PHP","readme":"# WordPress HTTP\n\nWordPress HTTP library.\n\n## Usage\n\n```php\n$response = Http::request( $url, $args );\n\n$data = $response-\u003ejson();\n```\n\n## Testing\n\n### Faking Responses\n\n```php\n$url = 'https://www.pronamic.nl/wp-json/wp/v2/types/post';\n\nHttp::fake( $url, __DIR__ . '/../http/pronamic-nl-wp-json-types-post.http' );\n\n$response = \\wp_remote_get( $url );\n\n// or\n\n$response = Http::get( $url );\n```\n\n### PHPUnit\n\n```php\n\u003c?php\n\nnamespace YourNamespace;\n\nuse Pronamic\\WordPress\\Http\\Factory;\n\nclass YourTest extends \\WP_UnitTestCase {\n\t/**\n\t * Setup.\n\t */\n\tpublic function setUp() {\n\t\tparent::setUp();\n\n\t\t$this-\u003efactory = new Factory();\n\t}\n\n\t/**\n\t * Test request.\n\t */\n\tpublic function test_request() {\n\t\t$this-\u003efactory-\u003efake( 'http://example.com/', __DIR__ . '/../http/example-com.http' );\n\n\t\t$result = \\wp_remote_get( 'http://example.com/' );\n\n\t\t// asserts\n\t}\n}\n\n```\n\n### CR LF\n\nTo store fake HTTP responses in `*.http` files and Git, keep the following in mind:\n\n\u003e HTTP/1.1 defines the sequence CR LF as the end-of-line marker for all protocol elements\n\nhttps://tools.ietf.org/html/rfc2616#section-2.2\n\n**`.gitattributes`**\n\n```\n*.http text eol=crlf\n```\n\nYou can use a tool like `unix2dos` to convert the line endings to CR LF:\n\n```\nunix2dos *.http\n```\n\nIf the line endings are not correct this can result in the following error:\n\n```\nUndefined offset: 2\n\nwordpress/wp-includes/class-http.php:732\nsrc/Factory.php:97\nwordpress/wp-includes/class-wp-hook.php:292\nwordpress/wp-includes/plugin.php:212\nwordpress/wp-includes/class-http.php:257\nwordpress/wp-includes/class-http.php:626\nwordpress/wp-includes/http.php:162\nsrc/Facades/Http.php:71\n```\n\n## Inspiration\n\n- https://github.com/WordPress/WordPress/blob/5.7/wp-includes/class-http.php\n- https://www.php-fig.org/psr/psr-7/\n- https://github.com/guzzle/psr7\n- https://github.com/jdgrimes/wp-http-testcase\n- https://docs.guzzlephp.org/en/stable/testing.html\n- https://github.com/guzzle/guzzle\n- https://github.com/namshi/cuzzle\n- https://docs.guzzlephp.org/en/stable/handlers-and-middleware.html\n- https://laravel.com/docs/8.x/http-client#faking-responses\n- https://www.php-fig.org/psr/psr-18/\n\n[![Pronamic - Work with us](https://github.com/pronamic/brand-resources/blob/main/banners/pronamic-work-with-us-leaderboard-728x90%404x.png)](https://www.pronamic.eu/contact/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpronamic%2Fwp-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpronamic%2Fwp-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpronamic%2Fwp-http/lists"}