{"id":15173072,"url":"https://github.com/nuxy/headless","last_synced_at":"2025-10-01T10:31:16.027Z","repository":{"id":142640299,"uuid":"49365870","full_name":"nuxy/headless","owner":"nuxy","description":"Expose Drupal 8 user operations as routes that support the JSON exchange format.","archived":true,"fork":false,"pushed_at":"2020-07-25T23:12:24.000Z","size":49,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-27T10:41:11.468Z","etag":null,"topics":["api","drupal8","end-of-life","module","no-support","php","reference"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nuxy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2016-01-10T12:27:51.000Z","updated_at":"2023-04-03T22:46:06.000Z","dependencies_parsed_at":"2023-04-07T09:00:22.209Z","dependency_job_id":null,"html_url":"https://github.com/nuxy/headless","commit_stats":{"total_commits":68,"total_committers":2,"mean_commits":34.0,"dds":0.02941176470588236,"last_synced_commit":"6f2aa14620f74425f1ef523f13b2ccbc932be218"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Fheadless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Fheadless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Fheadless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nuxy%2Fheadless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nuxy","download_url":"https://codeload.github.com/nuxy/headless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234858829,"owners_count":18897817,"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","drupal8","end-of-life","module","no-support","php","reference"],"created_at":"2024-09-27T10:40:41.447Z","updated_at":"2025-10-01T10:31:15.654Z","avatar_url":"https://github.com/nuxy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Headless\n\nExpose Drupal 8 user operations as routes that support the JSON exchange format.\n\n## Features\n\n- A configurable path that provides User Login, Register, Password Reset, and Account form handlers.\n- Post-process hooks for customizing JSON response data on request success.\n- Support for `application/json` Content-Type for POST requests and related responses.\n- Easy integration into [AngularJS](https://angularjs.org), [EmberJS](http://emberjs.com), or [jQuery](https://jquery.com) applications - No custom headers or tokens required.\n\n## Installation\n\n- Download the latest [release](https://github.com/nuxy/headless/tags).\n- Extract the contents of the _.zip_ into: `\u003cdrupal root\u003e/modules/contrib/`\n\n## Set-up\n\nOnce the module has been installed/enabled, you can navigate to `admin/config/services/headless` **(Configuration \u003e Web Services \u003e Headless in the Admin panel)** to configure the publicly accessible Routing Path.\n\n## Dependencies\n\n- [CORS](https://github.com/piyuesh23/cors) _(Optional, but recommended)_\n\n## Hooks\n\n#### hook_headless_response_alter()\n\nThe `FormState` instance is returned that includes the `form_id` and field values.  In cases where this in NOT preferred you can override the response data prior to sending.\n\n```\nfunction hook_headless_response_alter(array \u0026$data) {\n\n  // Preprocess Login responses.\n  if ($data['form_id'] == 'user_login_form') {\n\n    // Return nothing.\n    $data = NULL;\n  }\n}\n```\n\n#### hook_headless_request_alter()\n\nWhen using custom field parameter names in your client-side application you can alter these values prior to `FormState` validation.\n\n```\nfunction hook_headless_request_alter(array \u0026$params) {\n\n  // Preprocess request parameters.\n  if (isset($params['name'])) {\n\n    // Add prefix to key name.\n    $params['field_name'] = $params['name'];\n    unset($params['name']);\n  }\n}\n```\n\n## JavaScript Examples\n\n### User Login\n\nUsing the AngularJS [$http](https://docs.angularjs.org/api/ng/service/$http) service.\n\n```\n$http({\n  method: 'POST',\n  url:    '/headless/user/login',\n  cache:  false,\n  data: {\n    name: '\u003cname\u003e',\n    pass: '\u003cpass\u003e'\n  },\n  withCredentials: true\n})\n.then(\n  function successCallback(response) {},\n\n  // handle errors\n  function errorCallback(response) {\n    if (response.status === 400) {}\n    if (response.status === 500) {}\n  }\n);\n```\n\nUsing the jQuery [$ajax](http://api.jquery.com/jquery.ajax) method.\n\n```\n$.ajax({\n  type: 'POST',\n  url: '/headless/user/login',\n  dataType: 'json',\n  data: {\n    name: '\u003cname\u003e',\n    pass: '\u003cpass\u003e'\n  },\n  cache: false,\n  statusCode: {\n\n    // login success\n    202: function(data) {},\n\n    // handle errors\n    400: function() {},\n    500: function() {}\n  },\n  xhrFields: {\n    withCredentials: true\n  }\n});\n```\n\n### User Register\n\nUsing the AngularJS [$http](https://docs.angularjs.org/api/ng/service/$http) service.\n\n```\n$http({\n  method: 'POST',\n  url:    '/headless/user/register',\n  cache:  false,\n  data: {\n    mail: '\u003cmail\u003e',\n    name: '\u003cname\u003e',\n    pass: '\u003cpass\u003e'\n  }\n})\n.then(\n  function successCallback(response) {},\n\n  // handle errors\n  function errorCallback(response) {\n    if (response.status === 400) {}\n    if (response.status === 500) {}\n  }\n);\n```\n\nUsing the jQuery [$ajax](http://api.jquery.com/jquery.ajax) method.\n\n```\n$.ajax({\n  type: 'POST',\n  url: '/headless/user/register',\n  dataType: 'json',\n  data: {\n    mail: '\u003cmail\u003e',\n    name: '\u003cname\u003e',\n    pass: '\u003cpass\u003e'\n  },\n  cache: false,\n  statusCode: {\n\n    // login success\n    202: function(data) {},\n\n    // handle errors\n    400: function() {},\n    500: function() {}\n  }\n});\n```\n\n## Contributions\n\nIf you fix a bug, or have a code you want to contribute, please send a pull-request with your changes. (Note: Before committing your code please ensure that you are following the Drupal coding standards)\n\nYou can check your code by running the following command:\n\n    $ phpcs --standard=./vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml src\n\n## License and Warranty\n\nThis package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.\n\n_headless_ is provided under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.php)\n\n## Author\n\n[Marc S. Brooks](https://github.com/nuxy)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxy%2Fheadless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnuxy%2Fheadless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnuxy%2Fheadless/lists"}