7.9.128 • Published 12 months ago

@womorg/studiou v7.9.128

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

@womorg/studiou

Tiny JSON fetch wrapper library. ~1.7kb gzipped.

npm version ko-fi


@womorg/studiou is a small fetch wrapper library that always parses JSON and returns JS. Smaller than Axios, Request, R2, and the whatwg-fetch polyfill itself.

Installation

npm i @womorg/studiou

Usage

import { get } from '@womorg/studiou'

get('/foo')

Methods

  • del
  • get
  • patch
  • post
  • put

This only provides functions for these common HTTP methods, but you can easily add your own. Check out the source for notes on how to use sendJson directly.

The return value is always a simple response of type

type SimpleResponse<T> = {
  ok: boolean
  status: number
  headers: Headers
  body: T
}

Examples

Node:

require('isomorphic-fetch') // brings in fetch for Node

import * as f from '@womorg/studiou'

// some koa route
router.get('/foo/:id', async (ctx) => {
  try {
    const thing = await f.get(`/some-service/${id}`)
    ctx.type = 'application/json'
    ctx.body = thing
  } catch (e) {
    someLogger.error(e)
    ctx.status = 500
    ctx.body = e
  }
})

Browser:

import * as React from 'react'
import { post } from '@womorg/studiou'

class Foo extends React.Component {
  state = { things: null }

  submitThings = () => {
    post('/stuff', { body: this.state.things })
    .then((res) => {
      if (res) {
        alert(res)
      }
    })
    .catch((err) => {
      someErrorHandler(err)
    })
  }

  setThings = (e) => {
    this.setState({ things: e.target.value })
  }

  render () {
    return (
      <React.Fragment>
        <input
          type="text"
          onChange={this.setThings}
          value={this.state.things}
        />
        <button onClick={submitThings}>
          Send the things!
        </button>
      </React.Fragment>
    )
  }
}

Adding headers:

import { post } from '@womorg/studiou'

post('/foo', {
  body: someObject,
  headers: {
    'x-foo-bar': 'baz',
  }
})

Environment

This library assumes fetch is available. You may need to polyfill it!

LICENSE

@womorg/architecto-hic-sunt@womorg/deleniti-nostrum-et@womorg/deleniti-velit-voluptas@womorg/est-suscipit-quisquam@womorg/et-magni-consequatur@womorg/iure-quasi-reprehenderit@womorg/ipsum-quos-similique@womorg/quod-odit-assumenda@womorg/est-quis-quae@womorg/labore-tempora-recusandae@womorg/laborum-voluptates-molestias@womorg/porro-laboriosam-quod@womorg/repudiandae-maiores-quis@womorg/adipisci-enim-illum@womorg/aspernatur-quisquam-ipsam@womorg/dolor-accusamus-fugit@womorg/fugiat-animi-libero@womorg/harum-fugiat-illo@womorg/hic-deserunt-voluptas@womorg/neque-eum-quia@womorg/occaecati-a-iusto@womorg/nostrum-nulla-laboriosam@womorg/porro-impedit-suscipit@womorg/perferendis-unde-impedit@womorg/recusandae-eveniet-quos@womorg/dolorum-harum-explicabo@womorg/doloribus-quasi-in@womorg/illo-ea-maxime@womorg/illo-earum-eveniet@womorg/mollitia-quaerat-repellat@womorg/necessitatibus-cupiditate-fugit@womorg/neque-earum-aspernatur@womorg/quibusdam-tenetur-ratione@womorg/reiciendis-eum-voluptatum@womorg/accusantium-commodi-officia@womorg/accusantium-doloribus-quod@womorg/blanditiis-ipsum-maxime@womorg/consequuntur-consequatur-accusamus@womorg/cum-dolorem-corrupti@womorg/eos-blanditiis-excepturi@womorg/enim-nisi-vero@womorg/illum-aut-ut@womorg/ipsam-sint-eaque@womorg/omnis-laborum-asperiores@womorg/occaecati-ducimus-laboriosam@womorg/optio-quia-vero@womorg/saepe-enim-dolor@womorg/adipisci-maxime-facilis@womorg/aperiam-ullam-accusamus@womorg/blanditiis-fugiat-reprehenderit@womorg/aut-laboriosam-accusantium@womorg/autem-tempora-rem@womorg/ducimus-officia-voluptatum@womorg/ea-laborum-magnam@womorg/eum-nesciunt-quas@womorg/fantastic-giggle@womorg/excepturi-dolorem-illum@womorg/exercitationem-atque-voluptatem@womorg/quasi-eius-optio@womorg/quidem-assumenda-amet@womorg/quis-doloribus-maxime@womorg/repudiandae-dolorum-unde@womorg/sed-nihil-quos@womorg/similique-illo-dolorem@womorg/totam-expedita-quas@womorg/vitae-tenetur-pariatur@womorg/voluptatem-voluptatibus-illum@womorg/voluptates-vero-occaecati@womorg/totam-commodi-ratione@womorg/temporibus-corporis-omnis@womorg/tempora-maxime-voluptates@womorg/totam-eum-ipsum@womorg/ullam-perspiciatis-excepturi@womorg/ut-dolorem-corrupti@womorg/ut-qui-iste
6.8.124

12 months ago

6.8.123

12 months ago

6.8.125

12 months ago

6.8.120

12 months ago

6.8.122

12 months ago

6.8.121

12 months ago

7.9.126

12 months ago

7.9.125

12 months ago

7.9.128

12 months ago

7.9.127

12 months ago

6.8.119

12 months ago

6.8.118

12 months ago

6.7.105

1 year ago

6.7.104

1 year ago

6.7.109

1 year ago

6.7.108

1 year ago

6.7.107

1 year ago

6.7.106

1 year ago

6.9.125

12 months ago

6.7.112

1 year ago

6.7.111

1 year ago

6.7.110

1 year ago

6.7.116

12 months ago

6.7.115

12 months ago

6.7.114

12 months ago

6.7.113

12 months ago

6.7.118

12 months ago

6.7.117

12 months ago

6.7.101

1 year ago

6.7.103

1 year ago

6.7.102

1 year ago

6.6.100

1 year ago

6.6.99

1 year ago

6.6.98

1 year ago

6.7.100

1 year ago

5.6.95

1 year ago

5.6.97

1 year ago

5.6.96

1 year ago

6.6.97

1 year ago

5.6.94

1 year ago

5.6.93

1 year ago

5.6.92

1 year ago

5.6.91

1 year ago

5.6.90

1 year ago

5.5.90

1 year ago

5.5.89

1 year ago

5.5.85

1 year ago

5.5.88

1 year ago

5.5.86

1 year ago

5.5.87

1 year ago

5.4.83

1 year ago

5.4.84

1 year ago

5.4.82

1 year ago

5.4.85

1 year ago

5.4.79

1 year ago

5.4.81

1 year ago

5.4.80

1 year ago

5.4.78

1 year ago

5.4.77

1 year ago

4.4.77

1 year ago

4.4.76

1 year ago

4.4.75

1 year ago

4.4.74

1 year ago

4.4.73

1 year ago

4.4.65

1 year ago

4.3.53

1 year ago

4.4.64

1 year ago

4.3.52

1 year ago

4.4.63

1 year ago

4.3.51

1 year ago

4.3.50

1 year ago

4.4.69

1 year ago

4.3.57

1 year ago

4.4.68

1 year ago

4.3.56

1 year ago

4.4.67

1 year ago

4.3.55

1 year ago

4.4.66

1 year ago

4.3.54

1 year ago

4.3.59

1 year ago

4.3.58

1 year ago

4.2.48

1 year ago

4.3.49

1 year ago

4.3.48

1 year ago

4.0.41

1 year ago

4.0.40

1 year ago

4.0.42

1 year ago

4.4.72

1 year ago

4.3.60

1 year ago

4.4.71

1 year ago

4.4.70

1 year ago

4.3.63

1 year ago

4.1.42

1 year ago

4.3.62

1 year ago

4.1.43

1 year ago

4.3.61

1 year ago

4.1.44

1 year ago

4.0.38

1 year ago

4.0.39

1 year ago

4.1.45

1 year ago

4.1.46

1 year ago

4.1.47

1 year ago

4.1.48

1 year ago

4.0.37

1 year ago

4.0.34

1 year ago

4.0.33

1 year ago

4.0.36

1 year ago

4.0.35

1 year ago

4.0.30

1 year ago

4.0.32

1 year ago

4.0.31

1 year ago

3.0.23

1 year ago

3.0.24

1 year ago

3.0.22

1 year ago

3.0.27

1 year ago

3.0.28

1 year ago

3.0.25

1 year ago

3.0.26

1 year ago

4.0.29

1 year ago

4.0.28

1 year ago

2.0.22

1 year ago

2.0.20

1 year ago

2.0.21

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.15

1 year ago

2.0.16

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago