@lighthouseapps/request

    1.1.3 • Public • Published

    request

    Javascript http request library

    Usage

    import oauth2 from '@lighthouseapps/react-native-oauth2';
    import request from '@lighthouseapps/request';
    import io from 'socket.io-client';
    
    const router = {
      "createCode": {
        "uri": "/auth/authorize/:id",
        "method": "POST",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      },
      "createCodeToken": {
        "uri": "/auth/token",
        "method": "POST",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      },
      "getUsers": {
        "uri": "/users",
        "method": "GET",
        "listenHeaders": [
          "Authorization"
        ],
        "listenSocket": "users"
      },
      "getUser": {
        "uri": "/user",
        "method": "GET",
        "listenHeaders": [
          "Authorization"
        ],
        "listenSocket": "user/:id"
      }
    };
    
    const HOST = 'http://localhost:8080';
    
    const io = require('socket.io-client');
    
    const socket = io(HOST);
    
    async function test() {
      await request.initialize(router, {
        baseURL: HOST,
        timeout: 10000,
        onHeaders: {
          Authorization: async () => {
            const token = await oauth2.getToken();
    
            return 'Bearer ' + token.access_token;
          }
        },
        socket
      });
    
      request.on('getUser', (err, res) => {
        if(err) console.log(err);
    
        console.log(res);
      });
    
      request.getUser()
        .then(res => console.log(res))
        .catch(err => console.log(err));
    }
    
    test();

    Keywords

    none

    Install

    npm i @lighthouseapps/request

    DownloadsWeekly Downloads

    19

    Version

    1.1.3

    License

    MIT

    Unpacked Size

    12.1 kB

    Total Files

    11

    Last publish

    Collaborators

    • leosampc
    • marlonconstante
    • gustavo-kuze
    • donnes
    • alvarosilveiraa
    • lhdev