Git Product home page Git Product logo

roi's Introduction

roi

Coverage Status Build Status Known Vulnerabilities dependencies Status

NPM

A basic and fast REST http-client library.

Project Info
License: Apache-2.0
Build: make
Documentation: http://bucharest-gold.github.io/roi
Issue tracker: https://github.com/bucharest-gold/roi/issues
Engines: Node.js 4.x, 6.x, 7.x

Installation

npm install roi -S

Usage

    const roi = require('roi');

    const options = {
      'endpoint': 'http://localhost:3000/posts'
    };

    roi.get(options)
    .then(x => {
       console.log(x);
       console.log(x.statusCode);
       console.log(x.headers);
       console.log(x.body);
     })
    .catch(e => console.log(e));

More examples

POST
    const options = {
      'endpoint': 'http://localhost:3000/posts'
    };

    const foo = {
      title: 'foo-json',
      author: 'bgold'
    };

    roi.post(options, foo)
    .then(x => console.log(x))
    .catch(e => console.log(e));
PUT
    const options = {
      'endpoint': 'http://localhost:3000/posts/2'
    };

    const foo = {
      title: 'foo-json2',
      author: 'bgold'
    };

    roi.put(options, foo)
    .then(x => console.log(x))
    .catch(e => console.log(e));
DELETE
    const options = {
      'endpoint': 'http://localhost:3000/posts/3'
    };

    roi.del(options)
    .then(x => console.log(x))
    .catch(e => console.log(e));
EXISTS
    const options = {
      'endpoint': 'http://localhost:3000/posts/3'
    };

    roi.exists(options)
    .then(x => console.log(x.statusCode === 200))
    .catch(e => console.log(e));
DOWNLOAD
    const opts = {
      'endpoint': 'http://central.maven.org/maven2/org/jboss/aesh/aesh/0.66.8/aesh-0.66.8.jar'
    };
    roi.download(opts, '/tmp/aesh.jar')
    .then(x => console.log(x))
    .catch(e => console.log(e));
UPLOAD
    // Fake server side app will save the file called uploaded.jar :
    const up = (request, response) => {
      request
        .pipe(fs.createWriteStream('/tmp/uploaded.jar'))
        .on('finish', () => {
          response.end(request.headers.filename);
        });
    };
    const server = require('http').createServer(up);
    server.listen(3002, () => {});
    
    // Upload and check if the uploaded file exists:
    const opts = {
      'endpoint': 'http://localhost:3002/'
    };
    roi.upload(opts, '/tmp/aesh.jar')
    .then(x => {
      try {
        fs.statSync('/tmp/uploaded.jar');
      } catch (e) {
        console.error(e);
      }
    });
Basic authentication
    // Add the username and password:
    const opts = {
      'endpoint': 'http://localhost:3000/',
      'username': 'admin',
      'password': 'admin'
    };
    roi.get(opts)
    .then(x => console.log(x))
    .catch(e => console.log(e));

Contributing

Please read the contributing guide

roi's People

Contributors

helio-frota avatar pavolloffay avatar felipewmartins avatar tiagofabre avatar

Watchers

James Cloos avatar Lucas Holmquist avatar  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.