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

react-retrofit

v1.0.7

Published

A Retrofit like axios implementation for react native

Downloads

4

Readme

react-retrofit

A Retrofit like axios implementation for react native

#Setup package.json

"dependencies": {
    "axios":"^0.19.0",
    "@react-native-community/async-storage":"^1.7.1"
  },
  "devDependencies": {
    "@babel/plugin-proposal-decorators":"^7.7.4"
  },

Setup babel.config.js

  plugins: [
    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]

Network Usage

import { Get, Token, Auth, OnRefresh } from 'react-retrofit'
import axios from 'axios'
class API {

  // pass access_token to API refresh_token is optional
  /**
    * @param {string} url
    * @param {AxiosRequestConfig} config
  */
  @AUTH('host/oauth')
  auth(data) {
    //transform data
    return {access_token:data.access_token, refresh_token:data.refresh_token}
  }

  //This will be called when status 401 occurred
  //Please return axios or promise with access_token refresh_token is optional
  @OnRefreshToken()
  refreshToken(refreshToken) {
    return axios({
      method: 'post',
      url: "http://xxx.xxx.com/oauth?grant_type=refresh_token&refresh_token="+refreshToken,
    }).then(result => { return { access_token: result.data.access_token } })
  }

  /**
    * @param {string} url
    * @param {AxiosRequestConfig} config
  */
  @Get('host/me')
  me(info) {
    //transform data
    console.log(info)
    return info
  }

  /**
    * @param {string} url
    * @param {AxiosRequestConfig} config
  */
  @Get('/photo')
  @Token //This will pass access_token to url automatically if @AUTH has been called
  photo(photo) {
    //transform data
    console.log(photo)
    return photo
  }
}

const api = new API()
api.auth()

api.me().then(info => {
    //data you transform
    console.log(info)
})

api.photo().then(photo => {
    //data you transform
    console.log(photo)
})

FlatList Usage

import { List } from 'react-retrofit'
import React, {Text} from 'react'
class App extends React.Component {

    const item = ({ name }) => { return (<Text>{name}</Text>) }

    /**
      * @param {React.Component} component
      * @param {string} url
      * @param {React.Component} listItem
      * @param {RetrofitConfig} config
      */
    @List("Main", "host/endpoint", item)

    //api return like [{"name":"Harry"},{"name":"Billy"}]. Attributes will auto bind to itemView

    render() {
        <this.Main />
    }
}

FlatList With API Usage

import React, {Text} from 'react'
import { List, ListWithAPI, Get } from 'react-retrofit'

class API {

  id = 0

  @Get('http://host/endpoint/')
  fetchData(data) {
    return data
  }

  @Get('http://host/endpoint/{id}')
  fetchMore(data) {
    this.id += 1
    return data
  }
}

const api = new API()

class App extends React.Component {

    const item = ({ name }) => { return (<Text>{name}</Text>) }

    /**
      * @param {React.Component} component
      * @param {function name(data) {}} fetchAPI
      * @param {function name(data) {}} fetchNextAPI
      * @param {React.Component} listItem
      * @param {RetrofitConfig} config
      */
    @ListWithAPI("Main", api.fetchData, api.fetchMore, item)

    //api return like [{"name":"Harry"},{"name":"Billy"}]. Attributes will auto bind to itemView

    render() {
        <this.Main />
    }
}