{"id":15608570,"url":"https://github.com/alorel/rx-ajax","last_synced_at":"2025-09-07T20:46:25.951Z","repository":{"id":90017093,"uuid":"299050165","full_name":"Alorel/rx-ajax","owner":"Alorel","description":"A basic utility wrapper for the rxjs ajax function","archived":false,"fork":false,"pushed_at":"2020-10-10T19:54:40.000Z","size":1654,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-04T15:24:57.479Z","etag":null,"topics":["rxjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Alorel.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":"2020-09-27T14:30:46.000Z","updated_at":"2020-10-10T19:54:10.000Z","dependencies_parsed_at":"2023-03-17T19:01:11.754Z","dependency_job_id":null,"html_url":"https://github.com/Alorel/rx-ajax","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"Alorel/basic-library-template-repo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Frx-ajax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Frx-ajax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Frx-ajax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alorel%2Frx-ajax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alorel","download_url":"https://codeload.github.com/Alorel/rx-ajax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246194881,"owners_count":20738759,"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":["rxjs"],"created_at":"2024-10-03T05:21:26.320Z","updated_at":"2025-03-29T14:25:28.322Z","avatar_url":"https://github.com/Alorel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rx-ajax\n\nA basic utility wrapper for rxjs allowing you to make configuration presets.\n\n[![CI](https://github.com/Alorel/rx-ajax/workflows/Core/badge.svg?branch=master)](https://github.com/Alorel/rx-ajax/actions?query=workflow%3ACore+branch%3Amaster+)\n[![Coverage Status](https://coveralls.io/repos/github/Alorel/rx-ajax/badge.svg?branch=master)](https://coveralls.io/github/Alorel/rx-ajax)\n[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Alorel/rx-ajax.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/Alorel/rx-ajax/context:javascript)\n\n-----\n\n# Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Extending an existing config](#extending-an-existing-config)\n  - [Middleware](#middleware)\n- [API](#api)\n  - [RxAjaxErrorResponse](#rxajaxerrorresponse)\n  - [RxAjaxOptions](#rxajaxoptions)\n  - [RxAjaxResponse](#rxajaxresponse)\n  - [RxAjax](#rxajax)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n# Installation\n\nAdd the registry to `.npmrc`:\n\n```bash\n@alorel:registry=https://npm.pkg.github.com\n```\n\nThen install the library:\n\n```bash\nnpm install rxjs@^6.0.0 @alorel/rx-ajax\n```\n\n# Usage\n\n```javascript\nimport {rxAjax} from '@alorel/rx-ajax';\nimport {ajax} from 'rxjs/ajax';\n\nconst api = rxAjax({\n  // Same options as regular rxjs ajax() plus some extras\n  headers: {\n    'content-type': 'text/json'\n  },\n  responseType: 'json'\n});\n\napi.post('/foo', {qux: 'baz'}, {timeout: 1, headers: {'x-foo': 'bar'}}).subscribe();\n// Equivalent to:\najax({\n  body: {qux: 'baz'},\n  headers: {\n    'content-type': 'text/json',\n    'x-foo': 'bar'\n  },\n  responseType: 'json',\n  timeout: 1\n}).subscribe();\n```\n\n## Extending an existing config\n\nEach `RxAjax` instance has an `.extend()` method that allows you to make a copy with a merged config:\n\n```javascript\napi.extend({\n  headers: {/*...*/}\n})\n```\n\n## Middleware\n\n`pre` middleware transforms the request, `post` middleware transforms a response. `preAsync` and `postAsync` do the\nsame, but return an `ObservableInput` instead.\n\n```javascript\napi.getJSON('/foo', {\n  pre: [],\n  preAsync: [],\n  post: [],\n  postAsync: []\n})\n```\n\nRefer to the API for middleware function signatures.\n\n# API\n\n## RxAjaxErrorResponse\n\n```typescript\nexport interface RxAjaxErrorResponse\u003cT = any\u003e extends Omit\u003cAjaxError, 'request' | 'response'\u003e {\n    request: RxAjaxRequestOptions;\n    response: T;\n}\n```\n\n## RxAjaxOptions\n\n```typescript\nexport declare type RxAjaxPostAsyncHook = \u003cI = any, O extends I = any\u003e(request: UnprocessedResponse\u003cI\u003e) =\u003e ObservableInput\u003cUnprocessedResponse\u003cO\u003e\u003e;\n\nexport declare type RxAjaxRequestOptions = Omit\u003cRxAjaxOptions, 'url'\u003e;\n\nexport declare type RxAjaxBodiedRequestOptions = Omit\u003cRxAjaxRequestOptions, 'body'\u003e;\n\nexport interface RxAjaxOptions extends Omit\u003cAjaxRequest, 'headers'\u003e {\n    headers?: Obj\u003cstring\u003e;\n    /** Middleware for the response */\n    post?: Arrayish\u003c(\u003cI = any, O extends I = any\u003e(response: UnprocessedResponse\u003cI\u003e) =\u003e UnprocessedResponse\u003cO\u003e)\u003e;\n    /** Async middleware for the response */\n    postAsync?: Arrayish\u003cRxAjaxPostAsyncHook\u003e;\n    /** Middleware for the request */\n    pre?: Arrayish\u003c((req: RxAjaxOptions) =\u003e RxAjaxOptions)\u003e;\n    /** Async middleware for the request */\n    preAsync?: Arrayish\u003c((req: RxAjaxOptions) =\u003e ObservableInput\u003cRxAjaxOptions\u003e)\u003e;\n}\n```\n\n## RxAjaxResponse\n\n```typescript\nexport interface RxAjaxResponse\u003cT = any\u003e extends Omit\u003cAjaxResponse, 'response' | 'request'\u003e {\n    request: RxAjaxOptions;\n    response: T;\n}\n\n/** Successful response */\nexport interface UnprocessedSuccessResponse\u003cT\u003e {\n    ok: true;\n    response: RxAjaxResponse\u003cT\u003e;\n}\n/** Unsuccessful response */\nexport interface UnprocessedErrorResponse\u003cT = any\u003e {\n    ok: false;\n    response: RxAjaxErrorResponse\u003cT\u003e;\n}\nexport declare type UnprocessedResponse\u003cT, E = any\u003e = UnprocessedSuccessResponse\u003cT\u003e | UnprocessedErrorResponse\u003cE\u003e;\n```\n\n## RxAjax\n\n```typescript\nexport interface RxAjax\u003cBaseT = any\u003e {\n    /** Make a DELETE request */\n    delete\u003cT = BaseT\u003e(url: string, opts?: RxAjaxRequestOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n    /**\n     * Extend the current default configuration with the given options\n     * @return a new {@link RxAjax} instance with the merged options\n     */\n    extend\u003cT = any\u003e(opts: RxAjaxOptions): RxAjax\u003cT\u003e;\n    /** Make a GET request */\n    get\u003cT = BaseT\u003e(url: string, opts?: RxAjaxRequestOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n    /** Make a GET request \u0026 set the responseType to \"json\" */\n    getJSON\u003cT = BaseT\u003e(url: string, opts?: RxAjaxRequestOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n    /** Make a PATCH request */\n    patch\u003cT = BaseT\u003e(url: string, body: any, opts?: RxAjaxBodiedRequestOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n    /** Make a POST request */\n    post\u003cT = BaseT\u003e(url: string, body: any, opts?: RxAjaxBodiedRequestOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n    /** Make a PUT request */\n    put\u003cT = BaseT\u003e(url: string, body: any, opts?: RxAjaxBodiedRequestOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n    /** Generic request function */ \u003cT = BaseT\u003e(urlOrRequest: string | RxAjaxOptions): Observable\u003cRxAjaxResponse\u003cT\u003e\u003e;\n}\n\n/** Create an rxjs.ajax wrapper with the given default options */\nexport declare function rxAjax\u003cBaseT = any\u003e(defaults?: RxAjaxOptions): RxAjax\u003cBaseT\u003e;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falorel%2Frx-ajax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falorel%2Frx-ajax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falorel%2Frx-ajax/lists"}