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

sophie-http

v1.0.8-beta

Published

Provides simple components for creating http requests. Ideal for an API

Downloads

11

Readme

Sophie HTTP

Provides simple components for creating http requests. Ideal for an API. It uses Promises.

Part of the framework Sophie

npm version npm dependencies npm downloads

INSTALLATION

yarn add sophie-http

USAGE

QUERY

To make a GET request use the Query object

// Import objects
import {
    Query,
    HtmlRequestContentType,
    XhrResponse
} from "sophie-http";

// Instantiate Query
const query: Query = new Query();

// Set the API endpoint
query.setUrl('api/posts');

// Make the request, returns a Promise
query.getData(new HtmlRequestContentType())
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

COMMAND

To make a POST, PUT or DELETE request use the Command object

// Import objects
import {
    Command,
    JsonRequestContentType,
    XhrResponse
} from "sophie-http";

// Instantiate Command
const command: Command = new Command();

// Set the API endpoint
command.setUrl('api/posts');

command.saveData(new JsonRequestContentType(), { title: "New post", text: "Lorem Ipsum... " })
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

command.updateData(new JsonRequestContentType(), { id: 1, title: "Updated title" })
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

command.deleteData(new JsonRequestContentType(), { id: 1 })
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

Extending Query or Command

For example, to pre-set the url

// Import objects
import {
    Query,
    Command,
    JsonRequestContentType,
    XhrResponse
} from "sophie-http";

const URI_API_POSTS = 'api/posts';

export class PostsQuery extends Query
{
	public constructor ()
	{
		super();
		this.url = URI_API_POSTS;
	}
}

export class PostsCommand extends Command
{
	public constructor ()
	{
		super();
		this.url = URI_API_POSTS;
	}
}

const postsQuery: Query = new PostsQuery();
const postsCommand: Command = new PostsCommand();

postsQuery.getData(new JsonRequestContentType())
    .then((res: XhrResponse) => {
        console.log(res);
    })
    .catch((res: XhrResponse) => {
        console.log(res);
    });

postsCommand.saveData(new JsonRequestContentType(), { title: "New post", text: "Lorem Ipsum... " })
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

postsCommand.updateData(new JsonRequestContentType(), { id: 1, title: "Updated title" })
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

postsCommand.deleteData(new JsonRequestContentType(), { id: 1 })
	.then((res: XhrResponse) => {
		console.log(res);
	})
	.catch((res: XhrResponse) => {
		console.log(res);
	});

Changelog

Changelog

Contributing contributions welcome

License

This software is licensed under the terms of the MIT license. See LICENSE for the full license.