npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vds-requests-cpr

v0.1.1

Published

React Native JSI cpr library

Downloads

26

Readme

vds-requests-cpr

React Native JSI wrapper for cpr curl HTTP client

###Features

  • High performance because everything is written in C++ (even the JS functions have C++ bodies!)
  • iOS, Android support

Installation

Import

import { JsiHttpRequests } from 'vds-requests-cpr';

Usage

//create instance
const http = new JsiHttpRequests({
  baseUrl: 'url',
  timeout: 1000,
}, /*isDebug*/ true)

//simple get request
const getResponse = await http.get<{id: string; name: string}>('/user/{id}', {
  params: {id: 20},
  timeout: 500,
})
if (getResponse.type === 'error') {
  console.log(getResponse.error)
} else {
  console.log(getResponse.data)
}

//simple post request, will never throw any errors
const postResponse = await http.post<any>('/post', {
  // also may be 'string' | 'json' | 'formUrlEncoded' | 'formData'
  json: {
    firstName: 'Fred',
    lastName: 'Flintstone'
  }
})
if (postResponse.type === 'error') {
  console.log(postResponse.error)
} else {
  console.log(postResponse.data)
}

//cancel request will throw expception with error status code 80
http.get<any>('/post', {
  requestId: 'uniqueRequestId'
})
http.cancelRequest('uniqueRequestId')

Default config passed on initialization

{
  baseURL: 'https://api.example.com',
  // `headers` are base headers will be passed to each request
  headers: {},
  paramsSerializer?: ParamsSerializer;
  errorInterceptor?: (request: JsiError) => Promise<JsiError>;
  // `timeout` specifies the number of milliseconds before the request times out.
  // If the request takes longer than `timeout`, the request will be aborted.
  timeout: 1000, // default is `0` (no timeout)
  timeout?: number;
  logRequest?: LogRequest;
  logResponse?: LogResponse;
  logErrorResponse?: LogError;
  skipResponseHeaders?: boolean;
  requestInterceptor?: RequestInterceptor;
}

Request Config


// Base request

{
  // `url` is the server URL that will be used for the request
  url: '/user/{id}';
  // `queries` are the URL query parameters to be sent with the request
  queries?: {orderBy: 'id'};
  // `params` params which will replace placeholders in url
  params?: {id: 12345};
  // `requestId` if not set will be generate automatically, request maybe cancelled with with id
  requestId?: '345';
  // `headers` are custom headers to be sent
  headers: {'X-Requested-With': 'XMLHttpRequest'},
  // `paramsSerializer` is an optional function in charge of serializing `params`
  // (e.g. https://www.npmjs.com/package/qs, http://api.jquery.com/jquery.param/)
  paramsSerializer: (queries) => QS.stringify(queries, {arrayFormat: 'brackets'}),
  // `timeout` specifies the number of milliseconds before the request times out.
  // If the request takes longer than `timeout`, the request will be aborted.
  timeout: 1000, // default is `0` (no timeout)
  // `baseURL` will be prepended to `url` unless `url` is absolute.
  // It can be convenient to set `baseURL` for an instance of axios to pass relative URLs
  // to methods of that instance.
  baseURL: 'https://some-domain.com/api',
  errorInterceptor: (error) => error
}

// Only applicable for request methods 'PUT', 'POST', 'DELETE' and 'PATCH'
{
  // syntax for `json`
  json: {
    firstName: 'Fred'
  }

  // syntax for `string`
  string: 'Fred'

  // syntax for `formUrlEncoded`
  formUrlEncoded: {
    firstName: 'Fred'
  }

  // syntax for `formData`
  formData: [
    // for file
    {name: 'fileName', path: 'absoluteFilePath'},
    {name: 'fileName2', path: 'absoluteFilePath'},
    // for other parameters
    {name: 'fileName', value: 'value'}
  ]
}

Response Schema

interface CommonResponse {
  // time which took for request
  readonly elapsed: number;
  // if skipResponseHeaders passed in defaultConfig is true
  // `headers` the HTTP headers that the server responded with
  // All header names are lower cased and can be accessed using the bracket notation.
  // Example: `response.headers['content-type']`
  readonly headers?: Record<string, string>;
  // request id
  readonly requestId: string;
  // full endpoint where request was made
  readonly endpoint: string;
  // `status` is the HTTP status code from the server response
  readonly status: number;
}

export interface JsiError extends CommonResponse {
  readonly type: 'error';
  // `error` is the response that was provided by the server
  error: string;
  // `data` is the response that was provided by the server on error
  readonly data?: string;
}

export interface JsiSuccess<T> extends CommonResponse {
  readonly type: 'success';
  // `data` is the response that was provided by the server
  readonly data: T;
}

export type JsiResponse<T> = JsiError | JsiSuccess<T>;

Tips

  1. Depending Another Android Library Containing libcrypto.so, libssl.so. vds-requests-cpr packages specified in Android C++ include libcrypto.so, libssl.so libraries. If a second library which also includes libcrypto.so, libssl.so is added as a dependency, gradle fails with More than one file was found with OS independent path lib/x86/libcrypto.so or lib/x86/libssl.so error message.

You can fix this error by adding the following block into your build.gradle.

android {
    packagingOptions {
        pickFirst 'lib/x86/libcrypto.so'
        pickFirst 'lib/x86/libssl.so'
        pickFirst 'lib/x86_64/libcrypto.so'
        pickFirst 'lib/x86_64/libssl.so'
        pickFirst 'lib/armeabi-v7a/libcrypto.so'
        pickFirst 'lib/armeabi-v7a/libssl.so'
        pickFirst 'lib/arm64-v8a/libcrypto.so'
        pickFirst 'lib/arm64-v8a/libssl.so'
    }
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT