npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

observable-json-rest-api-client

v0.1.0

Published

Send HTTP requests (POST, GET, PUT, and DELETE) to JSON REST Web services or other Web servers. Responses are packaged as RxJS Observables.

Downloads

6

Readme

observable-json-rest-api-client

Send HTTP requests to JSON REST Web services; receive responses as RxJS Observables.

Build Status npm npm Maintainability Known Vulnerabilities license

This package can send HTTP requests of type POST, GET, PUT, and DELETE; these types correspond to the CRUD operations (create, read, update, and delete) of a REST Web service. Any data sent is JSON, and attempts are made to parse any data received as JSON.

This package's API is:

	request(httpMethod, urlString, requestData, verbose = false)
	post(urlString, requestData, verbose = false)
	get(urlString, verbose = false)
	put(urlString, requestData, verbose = false)
	delete(urlString, verbose = false)

post(), get(), put(), and delete() are merely convenience functions that call request() with a specific httpMethod.

Each function returns an RxJS Observable that yields an object with the following fields:

  • statusCode : The HTTP status code from the response from the server
  • statusMessage : The HTTP status message from the response from the server
  • rawResponseBody : The raw body from the response from the server
  • jsonResponseBody : The body from the response from the server after it has been parsed as JSON. This field is only present if the response body was successfully parsed as JSON.
  • jsonParseError : The error, if any, that was encountered during the parsing of the response body as JSON.

Example 1: POST:

const engine = require('observable-json-rest-api-client');

const postData = {
	field1: 'abc',
	field2: 123
};

engine.post('https://httpbin.org/post', postData).subscribe(
	result => {
		console.log('POST: Result:', result);
		console.log('POST: Response body as JSON:', result.jsonResponseBody);
		console.log('POST: Posted data:', result.jsonResponseBody.data);
	},
	error => {
		console.error('POST: Error:', error);
	},
	() => {
		console.log('POST: Done.');
	}
);

Example 2: GET:

const engine = require('observable-json-rest-api-client');

engine.get('https://httpbin.org/uuid').subscribe(
	result => {
		console.log('GET: result:', result);
		console.log(`GET: HTTP response status: ${result.statusCode} ${result.statusMessage}`);
		console.log('GET: Response body as JSON:', result.jsonResponseBody);
		console.log('GET: UUID:', result.jsonResponseBody.uuid);
		console.log('GET: typeof UUID:', typeof result.jsonResponseBody.uuid);
	},
	error => {
		console.error('GET: Error:', error);
	},
	() => {
		console.log('GET: Done.');
	}
);

License

MIT