Nuclear Pumpkin Mocha

    @n0n3br/starwars-api-capture-serve

    0.0.3 • Public • Published

    StarWars API Capture and Local Serve

    Description

    A library to capture all data from Star Wars API (https://swapi.dev/) and serve it locally.


    Content


    About

    I made this library to use the Star Wars API in my learning projects without having to deal with the official api rate limit.

    All the data is captured and stored in a JSON file and then served with the JSON Server library.

    The official url's from the official api are replaced with the localhost:port syntax to make all the navigation between links local.

    The standard folder where the resulting json is stored is db, the default filename is swapi.json and the default serve port is 3000.


    Requirements

    To use this library you must have NodeJS installed in your machine.


    Instalation

    To install the library use npm:

    npm install @n0n3br/starwars-api-capture-serve
    

    How to use

    Create a folder to host your project

    mkdir my-project

    Run the npm init command

    cd my-project
    npm init -y

    Install the library

    npm i @n0n3br/starwars-api-capture-serve

    create a index.mjs file and write your script

    import fs from "fs";
    import path from "path";
    
    import { capture, serve } from "@n0n3br/starwars-api-capture-serve";
    
    const dbFolder = "db";
    const dbFile = "swapi.json";
    const port = 3000;
    
    // optional - check if the database file already exists
    // you can always capture a new database before serving, but you may have trouble wth the rate limit
    const dbPath = path.resolve(".", dbFolder, dbFile);
    if (!fs.existsSync(dbPath)) {
      // Capture function parameters are optional. If not informed, 'db' and 'swapi.json' values will be used
      await capture(dbFolder, dbFile);
    }
    // serve the resulting data
    // Serve function parameters are optional. If not informed 'db', 'swapi.json' and 3000 values will be used
    serve(dbFolder, dbFile, port);

    An usage example can also be found in the example folder


    Author

    Install

    npm i @n0n3br/starwars-api-capture-serve

    DownloadsWeekly Downloads

    36

    Version

    0.0.3

    License

    ISC

    Unpacked Size

    6.33 kB

    Total Files

    7

    Last publish

    Collaborators

    • n0n3br