1.0.2 • Published 6 years ago

definitely-typed-fetch-api v1.0.2

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

definitely-typed-fetch-api · GitHub license Build Status

A Node.js module that provides a typesafe wrapper class around the fetch api that is easily extendable

Installation

npm install definitely-typed-fetch-api --save
yarn add definitely-typed-fetch-api
bower install definitely-typed-fetch-api --save

Usage

TypeScript

import BaseService from './BaseService';
import { SmoothieOrderResponse, SmoothieOrder } from './smoothieServiceTypes';

class SmoothieService extends BaseService<SmoothieOrderResponse> {
    constructor() {
        super('www.smoothiecentral.com');
    }

    public async getSmoothieOrders(): Promise<SmoothieOrderResponse> {
        return await this.get(`${this.getServiceContext()}/smoothie/orders`);
    }

    public async createNewSmoothieOrder(order: SmoothieOrder): Promise<SmoothieOrderResponse> {
        return await this.post(`${this.getServiceContext()}/smoothie/createorder`, order);
    }

    public async modifySmoothieOrder(order: SmoothieOrderResponse): Promise<SmoothieOrderResponse> {
        return await this.update(`${this.getServiceContext()}/smoothie/createorder`, order);
    }

    public async deleteSmoothieOrder(orderId: string): Promise<SmoothieOrderResponse> {
        return await this.delete(`${this.getServiceContext()}/smoothie/deleteorder/${orderId}`);
    }

    protected testResponse(): Promise<SmoothieOrderResponse> {
        return new Promise((resolve, reject) => resolve({
            orderNumber: 1,
            smoothieOrders: [
                {
                    fruit: 'apple',
                    blendStyle: 'chunky',
                    size: 'medium',
                },
                {
                    fruit: 'apple',
                    blendStyle: 'chunky',
                    size: 'medium',
                }
            ]
        }));
    }

}

export default SmoothieService;

Test

npm run test
1.0.2

6 years ago

0.0.1

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago