Giter Site home page Giter Site logo

noe-http-client's Introduction

NOE-HTTP-Client

NOE-HTTP-Client = "NO Exception HTTP client".

This is a simple wrapper for module 'Request-Promise'. It suppresses the exception throwing in case of HTTP status Code greater than 400.

When you need this module?

Actually you don't need this module. With modules like "Request-Promise", you are able to make whatever HTTP-calls you like. The only downside of this approach is that you need to handle exceptions in case the return code is >= 400. While 401 or 403 makes sense for an exception, handle 404 is absolutely annoying, because semantically you can't say that it is an exception and I really hate to handle the exception if nothing is found in the database.

Another situation where I need a "no execption HTTP client" is to make HTTP calls within array.map, at latest when you call Promise.all() you'd better pray that every statusCode of the HTTP call is less than 400. You may argue that there are frameworks like "Q" which can help with this, but it is another dependency, isn't it?

This simple wrapper has been packaged als npm package and can be installed per command npm i noe-http-client

Installation

npm install noe-http-client

Usage and Data Structure

In its simplest case, you can use the module like following:

import { agent } from 'noe-http-client';
agent.get('https://www.google.com/test1234').then((res) => console.log(res));

The result will look like this:

HttpResult {
  statusCode: 404,
  headers:
   { 'content-type': 'text/html; charset=UTF-8',
     'referrer-policy': 'no-referrer',
     'content-length': '1569',
     date: 'Wed, 13 Feb 2019 21:21:10 GMT',
     'alt-svc': 'quic=":443"; ma=2592000; v="44,43,39"',
     connection: 'close' },
  body:
   '<!DOCTYPE html>\n<html lang=en> .....</html>\n' }

Please check the source code for more details description of the usage.

Source Code

Source code can be found at https://github.com/lif9e1/noe-http-client. Feel free to fork and contribute!

noe-http-client's People

Contributors

lif9e1 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.