{"id":15687308,"url":"https://github.com/giuseppeg/flight-request","last_synced_at":"2025-05-07T19:41:27.061Z","repository":{"id":15071157,"uuid":"17797500","full_name":"giuseppeg/flight-request","owner":"giuseppeg","description":"A Flight mixin for making XHR requests","archived":false,"fork":false,"pushed_at":"2014-11-02T11:13:30.000Z","size":219,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T22:07:04.689Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/giuseppeg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-16T11:10:59.000Z","updated_at":"2017-05-21T05:11:41.000Z","dependencies_parsed_at":"2022-07-16T21:33:09.667Z","dependency_job_id":null,"html_url":"https://github.com/giuseppeg/flight-request","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuseppeg%2Fflight-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuseppeg%2Fflight-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuseppeg%2Fflight-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuseppeg%2Fflight-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giuseppeg","download_url":"https://codeload.github.com/giuseppeg/flight-request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252945401,"owners_count":21829582,"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":[],"created_at":"2024-10-03T17:47:03.895Z","updated_at":"2025-05-07T19:41:27.037Z","avatar_url":"https://github.com/giuseppeg.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flight-request\n\n[![Build Status](https://secure.travis-ci.org/giuseppegurgone/flight-request.png)](http://travis-ci.org/giuseppegurgone/flight-request)\n\nA [Flight](https://github.com/flightjs/flight) mixin for making XHR requests.\n\n## Installation\n\n```bash\nbower install --save flight-request\n```\n\n## Example\n```bash\ndefine(function (require) {\n\tvar defineComponent = require('flight/lib/component');\n  \tvar withRequest = require('flight-request/lib/with_request');\n\n\treturn defineComponent(dataComponent, withRequest);\n\n\tfunction dataComponent() {\n\t\tthis.after('initialize', function () {\n\t\t\tthis.get({\n\t\t\t\turl: 'http://b.ar/gimme-beer',\n\t\t\t\tsuccess: function () {\n\t\t\t\t\tconsole.log('Skål!');\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n});\n```\n\n## Methods and Events\n### Methods\nflight-request exposes the following methods:\n\n* `this.get`, `this.post`, `this.put`, `this.destroy` (you can also use `this.delete` if you are in a ES5 env) - return a jqXHR object [*].\n* `this.abort` takes a jqXHR object as parameter and aborts the given request.\n* `this.abortAllRequests` - to abort all the open xhr requests.\n\n[*] by default the requests can be aborted either with this.abort or this.abortAllRequest. If you want to prevent this to happen you can set `noAbort` to true and pass it along with the ajax settings\n\n#### callbacks context\nFrom v1.0.0 the default callbacks context is the component one.\nHowever you can change it by setting `context` in the ajax settings or using bind.\n\n```javascript\n// by default the callbacks context is the component one\nthis.get({\n\turl: 'http://b.ar/gimme-beer',\n\tsuccess: function () {\n\t\t// this === component\n\t\tthis.doSomething();\n\t}\n});\n\n\n// the context can be changed with bind or by setting the context property\nthis.get({\n\turl: 'http://b.ar/gimme-beer',\n\tcontext: 'foo',\n\tsuccess: function () {\n\t\t// this === 'foo'\n\t},\n\terror: function () {\n\t\t// this === 'bar'\n\t}.bind('bar')\n});\n```\n\n#### tunnelMethod - PUT and DELETE request tunnelling\n\u003cblockquote\u003eHTML forms (up to HTML version 4 and XHTML 1) only support GET and POST as HTTP request methods. \nA workaround for this is to tunnel other methods (PUT and DELETE) through POST by using a hidden form field \nwhich is read by the server and the request dispatched accordingly.\u003c/blockquote\u003e\n\n[http://stackoverflow.com/a/166501/931594](http://stackoverflow.com/a/166501/931594)\n\nMethod tunnelling is enabled by default for PUT and DELETE requests.\nIn those cases the request data object contains a `_method` property with the original request type (verb).\u003cbr\u003e\nFrom v1.0.0 it is possible to disable the tunnelling by setting `tunnelMethod` to `false` in the ajax settings.\u003cbr\u003e\nIt is also possible to change the tunnelling property name by setting `tunnelMethod` to a string of your choice (one time change)\u003cbr\u003e\nor via the component settings `this.attr.tunnelMethod`.\n\n\n### Events\nYou can specify custom events names (instead of functions) to be triggered on `success` and/or `error`.\nThanks to Angus Croll for the [suggestion](https://github.com/giuseppeg/flight-request/issues/1).\n\n```javascript\nthis.on('thereYouGo', function (event, responseData, textStatus, jqXHR) {\n\tconsole.log('Skål!');\n});\n\nthis.get({\n\turl: 'http://b.ar/gimme-beer',\n\tsuccess: 'thereYouGo'\n});\n```\n\nAll the requests are automatically aborted when the window is unloading its content and resources (window.onunload);\n…\n\n## Development\n\nDevelopment of this component requires [Bower](http://bower.io) to be globally\ninstalled:\n\n```bash\nnpm install -g bower\n```\n\nThen install the Node.js and client-side dependencies by running the following\ncommands in the repo's root directory.\n\n```bash\nnpm install \u0026 bower install\n```\n\nTo continuously run the tests in Chrome during development, just run:\n\n```bash\nnpm run watch-test\n```\n\n## Contributing to this project\n\nAnyone and everyone is welcome to contribute. Please take a moment to\nreview the [guidelines for contributing](CONTRIBUTING.md).\n\n* [Bug reports](CONTRIBUTING.md#bugs)\n* [Feature requests](CONTRIBUTING.md#features)\n* [Pull requests](CONTRIBUTING.md#pull-requests)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiuseppeg%2Fflight-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiuseppeg%2Fflight-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiuseppeg%2Fflight-request/lists"}