{"id":18780493,"url":"https://github.com/wunderwerkio/http-api-utils","last_synced_at":"2026-02-09T19:07:12.257Z","repository":{"id":150073562,"uuid":"621712514","full_name":"wunderwerkio/http-api-utils","owner":"wunderwerkio","description":"Set of useful HTTP API utilities. Provides json schema validation and error handling.","archived":false,"fork":false,"pushed_at":"2024-12-11T14:45:56.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-15T20:20:41.396Z","etag":null,"topics":["composer-package","http","http-api","php-library","php8","symfony"],"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/wunderwerkio.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2023-03-31T08:20:44.000Z","updated_at":"2024-12-11T14:46:48.000Z","dependencies_parsed_at":"2024-11-07T20:31:34.369Z","dependency_job_id":"0a6c6534-bd42-4edf-87c5-bf86e67219eb","html_url":"https://github.com/wunderwerkio/http-api-utils","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/wunderwerkio/http-api-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wunderwerkio%2Fhttp-api-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wunderwerkio%2Fhttp-api-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wunderwerkio%2Fhttp-api-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wunderwerkio%2Fhttp-api-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wunderwerkio","download_url":"https://codeload.github.com/wunderwerkio/http-api-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wunderwerkio%2Fhttp-api-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266552752,"owners_count":23947183,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["composer-package","http","http-api","php-library","php8","symfony"],"created_at":"2024-11-07T20:26:38.562Z","updated_at":"2026-02-09T19:07:07.209Z","avatar_url":"https://github.com/wunderwerkio.png","language":"PHP","readme":"# HTTP-API Utils\n\nThis package provides useful utilities for use with HTTP-APIs of any kind. \n\nFor response generation the `symfony/http-foundation` package is being used.\n\n## Install\n\nInstall this package via composer:\n\n```bash\ncomposer require wunderwerkio/http-api-utils\n```\n\n## Features\n\n### `HttpApiValidationTrait`\n\nThe `HttpApiValidationTrait` provides methods to validate a data structure against a [JSON Schema)(https://json-schema.org/).\nThe validation itself is done with the [`justinrainbow/json-schema`](https://github.com/justinrainbow/json-schema) package.\n\n**Define the schema**:\n\n```php\n$schema = [\n  \"type\" =\u003e \"object\",\n  \"properties\" =\u003e [\n    \"name\" =\u003e [\n      \"type\" =\u003e \"string\",\n    ],\n    \"age\" =\u003e [\n      \"type\" =\u003e \"integer\",\n    ],\n  ],\n  \"required\" =\u003e [\"name\"],\n];\n```\n\nDepending on your input data, you can use different validation methods to suit your needs:\n\n- `validateDataStructure`\n  Accepts a reference to an object. This is meant to be used with results from `json_decode`.\n- `validateArray`\n  Accepts an array as the data to validate. \n- `validateJsonString`\n  Accepts a JSON encoded string.\n\n**Example (with the schema from above)**:\n\n```php\n$validData = (object) [\n  'name' =\u003e 'Max',\n  'age' =\u003e 42,\n];\n\n$result = $this-\u003evalidateDataStructure($validData, $schema);\n\n$result-\u003eisValid(); // -\u003e TRUE\n\n// With invalid data.\n\n$invalidData = (object) [\n  'age' =\u003e '42',\n];\n\n$result = $this-\u003evalidateDataStructure($invalidData, $schema);\n\n$result-\u003eisValid(); // -\u003e FALSE\n$result-\u003egetErrors(); // -\u003e Array of validation errors.\n$result-\u003egetResponse(); // -\u003e JsonApiErrorResponse with the validation errors.\n```\n\nFor more information, check out the JSON Schema package: https://github.com/justinrainbow/json-schema.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwunderwerkio%2Fhttp-api-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwunderwerkio%2Fhttp-api-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwunderwerkio%2Fhttp-api-utils/lists"}