Skip to content

Refactor requests handling #2

@SpaceK33z

Description

@SpaceK33z

Currently requests in a model or store are done via src/request.js. This is kind of a global module. It doesn't offer enough flexibility and makes unit testing harder because it sets variables like baseUrl and csrfToken in the global module.

We could refactor this to a Request class. The user can initialize a Request class in it's own code (only needs to be done once), like this:

import { Request as BRequest } from 'mobx-binder';

class Request extends BRequest {
  baseUrl = 'http://localhost:8080/api/';
  csrfToken = 'xxx';

  get(...args) {
    // do custom stuff
    super().get(..args);
  }
}

If you want to make requests with a model or store, you need to pass in an initialized Request class. Otherwise it will give a clear error message that you need to pass such a class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions