7.9.128 • Published 10 months ago

@womorg/studiou v7.9.128

Weekly downloads
-
License
MIT
Repository
github
Last release
10 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

10 months ago

6.8.123

10 months ago

6.8.125

10 months ago

6.8.120

10 months ago

6.8.122

10 months ago

6.8.121

10 months ago

7.9.126

10 months ago

7.9.125

10 months ago

7.9.128

10 months ago

7.9.127

10 months ago

6.8.119

10 months ago

6.8.118

10 months ago

6.7.105

11 months ago

6.7.104

11 months ago

6.7.109

11 months ago

6.7.108

11 months ago

6.7.107

11 months ago

6.7.106

11 months ago

6.9.125

10 months ago

6.7.112

11 months ago

6.7.111

11 months ago

6.7.110

11 months ago

6.7.116

10 months ago

6.7.115

10 months ago

6.7.114

10 months ago

6.7.113

11 months ago

6.7.118

10 months ago

6.7.117

10 months ago

6.7.101

11 months ago

6.7.103

11 months ago

6.7.102

11 months ago

6.6.100

11 months ago

6.6.99

11 months ago

6.6.98

11 months ago

6.7.100

11 months ago

5.6.95

11 months ago

5.6.97

11 months ago

5.6.96

11 months ago

6.6.97

11 months ago

5.6.94

11 months ago

5.6.93

11 months ago

5.6.92

11 months ago

5.6.91

11 months ago

5.6.90

11 months ago

5.5.90

11 months ago

5.5.89

11 months ago

5.5.85

12 months ago

5.5.88

11 months ago

5.5.86

12 months ago

5.5.87

11 months ago

5.4.83

12 months ago

5.4.84

12 months ago

5.4.82

12 months ago

5.4.85

12 months ago

5.4.79

12 months ago

5.4.81

12 months ago

5.4.80

12 months ago

5.4.78

12 months ago

5.4.77

12 months ago

4.4.77

12 months ago

4.4.76

12 months ago

4.4.75

12 months ago

4.4.74

12 months ago

4.4.73

12 months 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

12 months 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

12 months ago

4.3.60

1 year ago

4.4.71

12 months ago

4.4.70

12 months 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