{"id":21557065,"url":"https://github.com/parable-php/http","last_synced_at":"2025-03-18T03:24:04.511Z","repository":{"id":57035824,"uuid":"177278305","full_name":"parable-php/http","owner":"parable-php","description":"Parable HTTP is a minimalist HTTP library used to receive requests and send responses.","archived":false,"fork":false,"pushed_at":"2025-02-20T18:12:37.000Z","size":59,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-20T19:19:24.481Z","etag":null,"topics":["http","minimalist","parable","php8","request","response"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/parable-php.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}},"created_at":"2019-03-23T11:03:16.000Z","updated_at":"2025-02-20T18:11:20.000Z","dependencies_parsed_at":"2022-08-23T22:10:46.822Z","dependency_job_id":null,"html_url":"https://github.com/parable-php/http","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parable-php%2Fhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parable-php","download_url":"https://codeload.github.com/parable-php/http/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244148339,"owners_count":20406160,"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":["http","minimalist","parable","php8","request","response"],"created_at":"2024-11-24T08:10:50.919Z","updated_at":"2025-03-18T03:24:04.492Z","avatar_url":"https://github.com/parable-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parable Http\n\n[![Workflow Status](https://github.com/parable-php/http/workflows/Tests/badge.svg)](https://github.com/parable-php/http/actions?query=workflow%3ATests)\n[![Latest Stable Version](https://poser.pugx.org/parable-php/http/v/stable)](https://packagist.org/packages/parable-php/http)\n[![Latest Unstable Version](https://poser.pugx.org/parable-php/http/v/unstable)](https://packagist.org/packages/parable-php/http)\n[![License](https://poser.pugx.org/parable-php/http/license)](https://packagist.org/packages/parable-php/http)\n\nParable Http is a minimalist Http library used to receive requests and send responses. It is not a full implementation, offering just-enough functionality.\n\n## Install\n\nPhp 8.0+ and [composer](https://getcomposer.org) are required.\n\n```bash\n$ composer require parable-php/http\n```\n\n## Usage\n\nTo create a `Request` object automatically from the server variables, use:\n\n```php\n$request = RequestFactory::createFromServer();\n```\n\nTo create a `Request` from scratch, use:\n\n```php\n$request = new Request(\n    'GET', \n    'http://url.here/path?param=value'\n);\n```\n\nTo set up a minimal response you want to send to the client:\n\n```php\n$response = new Response(200, 'This is the body');\n```\n\nAnd to send it, use the `Dispatcher`:\n\n```php\n$response = new Response(200, 'This is the body');\n$dispatcher = new Dispatcher();\n\n$dispatcher-\u003edispatch($response);\n```\n\nThis will send a response with stat\nus code `200`, with the body set as passed to the `Response` upon creation.\n\n## API\n\n### Request\n\n- `getMethod(): string` - returns GET, POST, etc.\n- `getUri(): Uri` - return a `Uri` object representing the uri being requested\n- `getRequestUri(): ?string` - the path of the `Uri`\n- `getProtocol(): string` - the protocol used (i.e. `HTTP/1.1`)\n- `getProtocolVersion(): string` - the version part of the protocol (i.e. `1.1`)\n- `getBody(): ?string` - the body of the request, if any\n- `getUser(): ?string` - the username from the uri\n- `getPass(): ?string` - the password from the uri\n- `isHttps(): bool` - whether the request was made over https. This represents a 'best guess' based on multiple checks\n- `isMethod(string $method): bool` - check whether the method matches `$method`\n\nFrom the `HasHeaders` trait:\n\n- `getHeader(string $header): ?string` - get a single header by string, `null` if non-existing\n- `getHeaders(): string[]` - get all headers\n\n### Response\n\n- `getBody(): ?string` - the body to be sent\n- `setBody(string $body): void` - set the body as a string \n- `prependBody(string $content): void` - prepend the value to the body\n- `appendBody(string $content): void` - append the value to the body\n- `getContentType(): string` - the content type (i.e. `text/html`, `application/json`)\n- `setContentType(string $contentType): void` - set the content type\n- `getProtocol(): string` - the protocol to be sent with (i.e. `HTTP/1.1`)\n- `getProtocolVersion(): string` - the protocol version (i.e. `1.1`)\n- `setProtocol(string $protocol): void` - set the protocol\n- `setHeaders(array $headers): void` - set multiple headers, resetting \n- `addHeaders(array $headers): void` - add multiple headers\n- `addHeader(string $header, string $value): void` - add single header\n\nFrom the `HasHeaders` trait:\n\n- `getHeader(string $header): ?string` - get a single header by string, `null` if non-existing\n- `getHeaders(): string[]` - get all headers\n\nFrom the `HasStatusCode` trait:\n\n- `getStatusCode(): int` - the status code to be sent (i.e. `200`)\n- `getStatusCodeText(): ?string` -  the status code text to be sent (i.e. `OK`)\n- `setStatusCode(int $statusCode): void` - set the status code \n\n### Dispatcher\n\n- `dispatch(Response $response): void` - dispatch a Response, sending all its content as set\n- `dispatchAndTerminate(Response $response, int $exitCode = 0): void` - dispatch a Response and terminate, i.e., ending program flow immediately afterwards \n\n\n## Contributing\n\nAny suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at [devvoh.com](https://devvoh.com).\n\n## License\n\nAll Parable components are open-source software, licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparable-php%2Fhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparable-php%2Fhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparable-php%2Fhttp/lists"}