@types/json-server
    TypeScript icon, indicating that this package has built-in type declarations

    0.14.4 • Public • Published

    Installation

    npm install --save @types/json-server

    Summary

    This package contains type definitions for json-server (https://github.com/typicode/json-server).

    Details

    Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/json-server.

    index.d.ts

    // Type definitions for json-server 0.14
    // Project: https://github.com/typicode/json-server
    // Definitions by: Jeremy Bensimon <https://github.com/jeremyben>
    // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
    // TypeScript Version: 2.3
    
    import { NextHandleFunction } from 'connect';
    import { Application, RequestHandler, Router } from 'express';
    import { LowdbSync } from 'lowdb';
    
    export interface JsonServerRouter<T> extends Router {
        db: LowdbSync<T>;
    }
    
    /**
     * Returns an Express server.
     */
    export function create(): Application;
    
    /**
     * Returns middlewares used by JSON Server.
     */
    export function defaults(options?: MiddlewaresOptions): RequestHandler[];
    
    /**
     * Returns JSON Server router.
     * @param source Either a path to a json file (e.g. `'db.json'`) or an object in memory.
     * This object will then be wrapped by lowdb, but you can also just pass in your own lowdb
     * instance that will then not be wrapped.
     * @param options Set foreign key suffix (default: `'Id'`)
     */
    export function router<T extends object>(source: LowdbSync<T> | T | string, options?: { foreignKeySuffix: string }): JsonServerRouter<T>;
    
    /**
     * Add custom rewrite rules.
     */
    export function rewriter(rules: { [rule: string]: string }): Router;
    
    /**
     * Returns body-parser middleware used by JSON Server router.
     *
     * @returns
     * ```
     * [bodyParser.json({ limit: '10mb', extended: false }), bodyParser.urlencoded({ extended: false })]
     * ```
     */
    export const bodyParser: [NextHandleFunction, NextHandleFunction];
    
    export interface MiddlewaresOptions {
        /**
         * Path to static files
         * @default "public" (if folder exists)
         */
        static?: string | undefined;
    
        /**
         * Enable logger middleware
         * @default true
         */
        logger?: boolean | undefined;
    
        /**
         * Enable body-parser middleware
         * @default true
         */
        bodyParser?: boolean | undefined;
    
        /**
         * Disable compression
         * @default false
         */
        noGzip?: boolean | undefined;
    
        /**
         * Disable CORS
         * @default false
         */
        noCors?: boolean | undefined;
    
        /**
         * Accept only GET requests
         * @default false
         */
        readOnly?: boolean | undefined;
    }

    Additional Details

    Credits

    These definitions were written by Jeremy Bensimon.

    Keywords

    none

    Install

    npm i @types/json-server

    DownloadsWeekly Downloads

    16,111

    Version

    0.14.4

    License

    MIT

    Unpacked Size

    7.24 kB

    Total Files

    4

    Last publish

    Collaborators

    • types