davestewart/axios-actions

How do you send body data with post requests using ApiGroup?

Closed this issue · 10 comments

How do you do it? I dont find any examples in the docs.

  const actions = {
    search: 'courses',
    update: 'POST products/widgets/:id',
    delete: 'DELETE products/widgets/:id',
  };

And the code below just replaces id.

widgets.use('update', 1)

But how can I send body data?

Did you create a Group?

export const widgets = new ApiGroup(axios, {
    search: 'courses',
    update: 'POST products/widgets/:id',
    delete: 'DELETE products/widgets/:id',
})

widgets.update({ id: 1, foo: 1 })

There's another ticket here, is that related?

@davestewart

Yes I am creating a group.

widgets.update({ id: 1, foo: 1 })

But this code just replaces foo and id like this:

products/widgets/:id/item/:foo

becomes

products/widgets/1/item/1

but I am trying to send data. How do I do that? I dont think that the tickets are related.

If you can update that last comment with full code so I can see what's happening, that would be helpful.

The URL will consume any placeholders, but the data should be sent in the POST body.

It's been a while since I looked at the code, so I might need to confirm if the full object is sent (I think it is) or the consumed fields are removed.

I am literally not doing anything beside following the example code in the docs for ApiGroup. That's why I am asking for help. You're completely right that the data should be sent through the POST body. But how do you do it? Do you have any examples I could look at?
Thanks.

Oh, so this is a question not a bug?

Any data you pass will be sent through the post body.

Did you check the network panel?

From the demo:

image

https://axios-actions.netlify.com/#/api/group

@davestewart

Yes this is a question. The example code is in vue so I dont really understand it. Could you please post some examples in vanilla js? Its a really simple question. How do I send data with post requests? If I had a login route, how would I send the email & password?
And I've looked at the docs several times and I dont find any examples. If you find any, then please post them here.

And I've looked at the docs several times and I dont find any examples.

This is the docs index page; every page has multiple examples, all in vanilla JS:

image

If you can't find or understand the examples, then that's not something I can help you with.

If you had a login route, you'd probably just send the username and password with a normal API call; AxiosActions is designed for sets of actions that you don't want to repeat in multiple places.

A login will only be in one place.

@davestewart

Arent you one of the contributors? How can you not help me?

const widgets = new ApiGroup(axios, {
    login: 'api/login'
})

widgets.call(login).then()

The code above exec the login action and gets the response. Now where in this code can I send the login info? I dont know why you keep referring to the docs because they dont have any examples...

How can you not help me?

I already did:

I dont know why you keep referring to the docs because they dont have any examples

Every page has multiple usage examples:

There is also a working demo for every class...

...each of which links to the related:

  • example file
  • source code
  • docs for that class