Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple configuration causes weird doubletting og req params #14

Open
klh opened this issue Apr 3, 2019 · 3 comments
Open

simple configuration causes weird doubletting og req params #14

klh opened this issue Apr 3, 2019 · 3 comments

Comments

@klh
Copy link

klh commented Apr 3, 2019

const actions = {

  // url only
  users: 'users',

  // url and param only
  user: 'users?id=:id',

  // url and object
  create: {
    method: 'post',
    url: 'users',
    headers: { 'Content-Type': 'application/json' }
  },

  // url and param only
  update: {
    method: 'put',
    url: 'users/:id/',
    headers: { 'Content-Type': 'application/json' }
  },

  // url and param only
  delete: {
    method: 'delete',
    url: 'users/:id/',
    headers: { 'Content-Type': 'application/json' }
  },

  // method and url
  getMethodUrl: 'GET users/:id',

  // request object
  getObject: {
    method: 'get',
    url: 'users/:id/',
    headers: { 'X-Custom-Header': 'foobar' }
  }
};

Jest test:

  it(' users getObject', async () => {
    const response = await users.getObject({"id":2});
    expect(response.data)
      .toMatchSpecificSnapshot('./__snapshots__/endpoints_user_search.shot');
  });

results in a get request to the endpoint like this:

/v1/users/2/?id=2

where it in reality should be:

/v1/users/2/
@klh
Copy link
Author

klh commented Apr 3, 2019

i realize it's sorta by design, but when using something like:

// method and url
  getMethodUrl: 'GET users/:id/:some/:thing',

readability increases when doing
user.getMethodUrl({"id":2, "some": 0, "thing":0})
instead of
user.getMethodUrl("2","0","0")

@klh klh closed this as completed Apr 3, 2019
@davestewart
Copy link
Owner

davestewart commented Apr 3, 2019

Hey, I see what you're saying and I think it's something I've considered before.

You're basically saying, for a GET request (or any request) when a param has been used in the URL, exclude it from the payload?

There's another post about this kind of thing as well. I wonder if should enable some kind of configuration. Possibly globally and per actions set, i.e.:

// global config
ApiCore.configure({ ... })

const actions = {
  _config: { ... }, // local config
  foo: 'foo/:id'
}

Or maybe a syntax:

 foo: 'foo/:id!'

What do you think?

@klh
Copy link
Author

klh commented Apr 3, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants