Skip to content

Instantly share code, notes, and snippets.

@oluosiname
Last active April 26, 2020 08:18
Show Gist options
  • Select an option

  • Save oluosiname/04f824927fdfeb1e5e73b1b1b8bd02e3 to your computer and use it in GitHub Desktop.

Select an option

Save oluosiname/04f824927fdfeb1e5e73b1b1b8bd02e3 to your computer and use it in GitHub Desktop.

Revisions

  1. oluosiname revised this gist Apr 26, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion http.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@ class Http {

    async get({ url, ...rest }) {
    const init = {...this.getInit, ...rest};

    try {
    const response = await fetch.get(url, init);
    return response.json();
    @@ -15,7 +16,7 @@ class Http {
    }
    }

    async post({ url, ...rest }) {
    async post({ url, body, ...rest }) {
    const init = {...this.postInit, ...rest};

    try {
  2. oluosiname created this gist Apr 25, 2020.
    28 changes: 28 additions & 0 deletions http.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@

    class Http {
    constructor() {
    this.postInit = { method: 'POST' }
    this.getInit = { method: 'GET' }
    }

    async get({ url, ...rest }) {
    const init = {...this.getInit, ...rest};
    try {
    const response = await fetch.get(url, init);
    return response.json();
    } catch (e) {
    throw e;
    }
    }

    async post({ url, ...rest }) {
    const init = {...this.postInit, ...rest};

    try {
    const response = await fetch(url, init);
    return response.json();
    } catch (e) {
    throw e;
    }
    }
    }