How to use wretch - 10 common examples

To help you get started, we’ve selected a few wretch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ififfy / flipflip / src / renderer / components / configGroups / APICard.tsx View on Github external
onFinishAuthReddit() {
    this.onCloseDialog();
    this.closeServer();
    const clientID = this.props.settings.redditClientID;
    const userAgent = this.props.settings.redditUserAgent;

    let deviceID = this.props.settings.redditDeviceID;
    if (deviceID == "") {
      deviceID = uuidv4();
    }

    // Make initial request and open authorization form in browser
    wretch("https://www.reddit.com/api/v1/authorize?client_id=" + clientID + "&response_type=code&state=" + deviceID +
      "&redirect_uri=http://localhost:65010&duration=permanent&scope=read,mysubreddits,history")
      .post()
      .res(res => {
        remote.shell.openExternal(res.url);
      })
      .catch(e => {
        console.error(e);
        this.setState({errorSnack: "Error: " + e.message});
        this.closeServer();
        return;
      });

    // Start a server to listen for Reddit OAuth response
    const server = http.createServer((req, res) => {
      // Can't seem to get electron to properly return focus to FlipFlip, just alert the user in the response
      const html = "<h1>Please return to FlipFlip</h1>";
github fanfoujs / space-fanfou / src / features / batch-remove-statuses / @page.js View on Github external
async function removeStatus(li) {
    const button = select(':scope > .op > .delete', li)
    // 删除普通消息时 `actionType` 为 "msg.del",删除图片消息时为 "photo.del"
    // 相应的 `fieldName` 分别应为 "msg" 和 "photo"
    const [ id, actionType ] = button.href.split('/').reverse()
    const fieldName = actionType.split('.')[0]
    const url = window.location.href
    const data = {
      ajax: 'yes',
      action: actionType,
      [fieldName]: id,
      token: button.getAttribute('token'),
    }
    const response = await wretch(url).formUrl(data).post().json()

    if (response.status) {
      window.FF.util.yFadeRemove(button, 'li')
    } else {
      notification.create(notification.ERROR, response.msg)
    }
  }
github ififfy / flipflip / src / renderer / data / actions.ts View on Github external
state.library[offset].url.startsWith("https://")) {
      state.progressTitle = state.library[offset].url;
      setState({progressTitle: state.progressTitle});
      const lastCheck = state.library[offset].lastCheck;
      if (lastCheck != null) {
        // If this link was checked within the last week, skip
        if (new Date().getTime() - new Date(lastCheck).getTime() &lt; 604800000) {
          state.progressCurrent = offset + 1;
          setState({progressCurrent: state.progressCurrent});
          setTimeout(offlineLoop, 100);
          return;
        }
      }

      state.library[offset].lastCheck = new Date();
      wretch(state.library[offset].url)
        .get()
        .notFound((res) =&gt; {
          state.library[offset].offline = true;
          state.progressCurrent = offset + 1;
          setState({progressCurrent: state.progressCurrent});
          setTimeout(offlineLoop, 1000);
        })
        .res((res) =&gt; {
          state.library[offset].offline = false;
          state.progressCurrent = offset + 1;
          setState({progressCurrent: state.progressCurrent});
          setTimeout(offlineLoop, 1000);
        })
        .catch((e) =&gt; {
          console.error(e);
          state.library[offset].lastCheck = null;
github snipsco / create-snips-action / static / src / factories / httpFactory.js View on Github external
const { default: wretch } = require('wretch')
const { dedupe } = require('wretch-middlewares')

const BASE_URL = 'https://pokeapi.co/api/v2'

const http = wretch(BASE_URL)
    // Add a dedupe middleware, throttling cache would also be useful to prevent excessive token usage.
    // (https://github.com/elbywan/wretch-middlewares)
    .middlewares([
        dedupe()
    ])

module.exports = {
    init(httpOptions = {}) {
        wretch().polyfills({
            fetch: httpOptions.mock || require('node-fetch')
        })
    },
    get() { return http }
}
github snipsco / create-snips-action / static / src / factories / httpFactory.js View on Github external
init(httpOptions = {}) {
        wretch().polyfills({
            fetch: httpOptions.mock || require('node-fetch')
        })
    },
    get() { return http }
github EQuimper / InStore-a-React-Native-E-Commerce-with-a-Restful-API-in-NodeJS / mobile / src / api / Api.js View on Github external
import wretch from 'wretch';

import { BASE_URL } from '../constants';

export const customersApi = wretch(`${BASE_URL}/customers`);
export const baseApi = wretch(BASE_URL);
github HAECHI-LABS / henesis-cli / src / rpc / user.spec.ts View on Github external
import { expect } from '@oclif/test';
import wretch from 'wretch';
import { baseUrl, rpcVersion } from './config';
import * as mockhttp from 'mockttp';
import { UserRpc } from './user';
import { DescribeResponse, LoginResponse } from '../types';
import { newMockLogin, newMockAccount } from '../mock';

wretch().polyfills({
  fetch: require('node-fetch'),
  FormData: require('form-data'),
  URLSearchParams: require('url').URLSearchParams,
});

process.env.HENESIS_TEST = 'true';
describe('UserRpc', (): void =&gt; {
  const mockServer = mockhttp.getLocal();
  let userRpc: UserRpc;

  beforeEach(
    async (): Promise =&gt; {
      const url = baseUrl();
      userRpc = new UserRpc(url, rpcVersion);
      await mockServer.start(8080);
    },
github elbywan / hyperactiv / src / react / hooks / useRequest.js View on Github external
export function useRequest(url, {
    store,
    client = wretch(),
    skip = () => false,
    beforeRequest = identity,
    afterRequest = identity,
    rootKey = defaultRootKey,
    serialize = defaultSerialize,
    bodyType = 'json',
    policy = 'cache-first',
    ssr = true
}) {
    const contextValue = useContext(HyperactivContext)
    const ssrContext = ssr && useContext(SSRContext)
    store = contextValue && contextValue.store || store
    client = contextValue && contextValue.client || client

    const configuredClient = useMemo(() => beforeRequest(client.url(url)), [client, beforeRequest, url])
    const storeKey = useMemo(() => serialize('get', configuredClient._url), [configuredClient])
github ififfy / flipflip / src / renderer / components / player / SourceScraper.tsx View on Github external
.text((html) =&gt; {
        let imageEls = new DOMParser().parseFromString(html, "text/html").querySelectorAll("#gdt &gt; .gdtm &gt; div &gt; a");
        if (imageEls.length &gt; 0) {
          let imageCount = 0;
          let images = Array();
          for (let image of imageEls) {
            wretch(image.getAttribute("href"))
              .get()
              .setTimeout(5000)
              .onAbort((e) =&gt; resolve(null))
              .notFound((e) =&gt; resolve(null))
              .text((html) =&gt; {
                imageCount++;
                let contentURL = html.match("
github 8th713 / cockpit-for-pixiv / packages / core / externals / apiClient.ts View on Github external
function fetchUgoira(illustId: string) {
    return wretch(`/ajax/illust/${illustId}/ugoira_meta`)
      .options({ credentials: 'same-origin', cache: 'no-cache' })
      .content('application/json')
      .errorType('json')
      .get()
      .json(data =&gt; data.body)
      .then(loadZip)
      .catch(handleError(`fetchUgoira(${illustId})`))
  }

wretch

A tiny wrapper built around fetch with an intuitive syntax.

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis

Popular wretch functions