Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ykzts/node-xmlhttprequest
server-side XMLHttpRequest for Node.
https://github.com/ykzts/node-xmlhttprequest
Last synced: 16 days ago
JSON representation
server-side XMLHttpRequest for Node.
- Host: GitHub
- URL: https://github.com/ykzts/node-xmlhttprequest
- Owner: ykzts
- License: mit
- Created: 2012-06-14T19:40:52.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2023-12-18T07:53:12.000Z (11 months ago)
- Last Synced: 2024-10-03T12:24:10.102Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/w3c-xmlhttprequest
- Size: 1.65 MB
- Stars: 42
- Watchers: 4
- Forks: 12
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# w3c-xmlhttprequest [![Node.js CI](https://github.com/ykzts/node-xmlhttprequest/workflows/Node.js%20CI/badge.svg)](https://github.com/ykzts/node-xmlhttprequest/actions?query=workflow%3A%22Node.js+CI%22)
Server-side XMLHttpRequest like [Living Standard](https://xhr.spec.whatwg.org/) for [Node](https://nodejs.org/).
## Install
```console
$ npm install w3c-xmlhttprequest
```or
```console
$ yarn add w3c-xmlhttprequest
```## Example
### Simple GET request
```typescript
import { XMLHttpRequest } from 'w3c-xmlhttprequest';const client = new XMLHttpRequest();
client.open('GET', 'https://example.com/');
client.addEventListener('load', () => {
console.log('Received an HTTP response.');
}
client.send();
```### Parse JSON response
```typescript
import { XMLHttpRequest } from 'w3c-xmlhttprequest';const client = new XMLHttpRequest();
client.open('GET', 'https://exmaple.com/data.json');
client.responseType = 'json';
client.addEventListener('load', () => {
const data = client.response;
if (data.meta.status !== 200) return;
console.log(data.response.blog.title);
});
client.send();
```## LICENSE
[MIT License](LICENSE)