How to use the wretch function in wretch

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 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})`))
  }
github fanfoujs / space-fanfou / src / features / notifications / service@background.js View on Github external
async function fetchFanfouMobileDOM() {
    try {
      const html = await wretch(URL_FANFOU_M_HOME).get().setTimeout(AJAX_TIMEOUT).text()
      const document = parseHTML(html)

      return document
    } catch (error) {
      log.info(`获取 m.fanfou.com 页面源码失败 @ ${timestamp()}`, error)
      return null
    }
  }
github ififfy / flipflip / src / renderer / components / player / SourceScraper.tsx View on Github external
.text((html) =&gt; {
          let albumEls = new DOMParser().parseFromString(html, "text/html").querySelectorAll("td.blk_galleries &gt; font &gt; a.blk_galleries");
          if (albumEls.length == 0) {
            helpers.next = null;
            resolve({data: [], helpers: helpers});
          } else if (albumEls.length &gt; helpers.next[1]) {
            let albumEl = albumEls[helpers.next[1]];
            let albumID = albumEl.getAttribute("href").substring(albumEl.getAttribute("href").lastIndexOf("/") + 1);
            wretch("http://www.imagefap.com/gallery/" + albumID + "?view=2")
              .get()
              .text((html) =&gt; {
                let imageEls = new DOMParser().parseFromString(html, "text/html").querySelectorAll(".expp-container &gt; form &gt; table &gt; tbody &gt; tr &gt; td");
                if (imageEls.length &gt; 0) {
                  let images = Array();
                  let imageCount = 0;
                  for (let image of imageEls) {
                    wretch("http://www.imagefap.com/photo/" + image.id + "/")
                      .get()
                      .text((html) =&gt; {
                        imageCount++;
                        let contentURL = html.match("\"contentUrl\": \"(.*?)\",");
                        if (contentURL != null) {
                          images.push(contentURL[1]);
                        }
                        if (imageCount == imageEls.length) {

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