Nanobots Producing Megastructures

    @testjg/nativescript-http
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    @testjg/nativescript-http

    npm version

    Http helper lib. Under the hood it uses okhttp (v3) for Android and NSURLSession for iOS.

    Has peer dependencies on url-join and rxjs.

    Installation

    ns plugin add @testjg/nativescript-http

    Usage

    import { createHttp, forRelativeUrl } from '@testjg/nativescript-http';
    import { firstValueFrom } from 'rxjs';
    import { catchError, switchMap } from 'rxjs/operators';
    
    export class TodosService {
      http = createHttp('https://jsonplaceholder.typicode.com');
      todos = forRelativeUrl('todos', this.http);
    
      fetchTodo(id: number) {
        const json$ = this.todos
          .request({
            method: 'GET',
            url: `${id}`,
            headers: { 'Accept-Language': ['ca', 'en'] },
          })
          .pipe(
            switchMap((res) => res.json()),
            catchError((error) => null)
          );
    
        return firstValueFrom(json$);
      }
    }

    Pro tip: Use functions like jsonBody or multiPartBody to create the appropiate request content.

    License

    Apache License Version 2.0

    Install

    npm i @testjg/nativescript-http

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    Apache-2.0

    Unpacked Size

    49.2 kB

    Total Files

    13

    Last publish

    Collaborators

    • jberga