Legitcode/legible

onResponse in requests

zackify opened this issue · 2 comments

What if we did:

import { partial } from 'legible'

const twitter = {
  register: partial`
    url: https://api.twitter.com/register,
    method: POST
    headers: ${{ Authorization: localStorage.getItem('authorization') }}
    onResponse: ${response => {
      localStorage.setItem({ authorization: response.headers.get('Authorization') })
    }}
  `
}

twitter.register`
  body: ${{
    email: 'test@test.com',
    password: 'Tester'
  }}
`

Thoughts?

I like it. Very flexible and don't need a full "middleware" solution.

This is done and has been for a bit. works great!