GithubHelp home page GithubHelp logo

iriberri / simplerestclients Goto Github PK

View Code? Open in Web Editor NEW

This project forked from microsoft/simplerestclients

0.0 1.0 0.0 122 KB

A simple set of wrappers for RESTful calls

License: MIT License

JavaScript 3.83% TypeScript 96.17%

simplerestclients's Introduction

SimpleRestClients

GitHub license npm version npm downloads Build Status David David

A simple set of wrappers for RESTful calls. Consists of two modules:

SimpleWebRequest

Wraps a single web request. Has lots of overrides for priorization, delays, retry logic, error handling, etc.

GenericRestClient

Wraps SimpleWebRequest for usage across a single RESTful service. In our codebase, we have several specific RESTful service interaction classes that each implement GenericRestClient so that all of the requests get the same error handling, authentication, header-setting, etc.

GenericRestClient Sample Usage

import { GenericRestClient, ApiCallOptions }  from 'simplerestclients';
import SyncTasks = require('synctasks');

interface User {
    id: string;
    firstName: string;
    lastName: string;
}

class MyRestClient extends GenericRestClient {
    constructor(private _appId: string) {
        super('https://myhost.com/api/v1/');
    }

    // Override _getHeaders to append a custom header with the app ID.
    protected _getHeaders(options: ApiCallOptions): { [key: string]: string } {
        let headers = super._getHeaders(options);
        headers['X-AppId'] = this._appId;
        return headers;
    }

    // Define public methods that expose the APIs provided through
    // the REST service.
    getAllUsers(): SyncTasks.Promise<User[]> {
        return this.performApiGet<User[]>('users');
    }

    getUserById(id: string): SyncTasks.Promise<User> {
        return this.performApiGet<User>('user/' + id);
    }

    setUser(user: User): SyncTasks.Promise<void> {
        return this.performApiPut<void>('user/' + user.id, user);
    }
}

simplerestclients's People

Contributors

a-tarasyuk avatar berickson1 avatar deregtd avatar kubocob avatar ms-deregtd avatar ms-markda avatar plisy avatar rbravo avatar seriousjul avatar

Watchers

 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.