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

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

Closed
nimabrownlee opened this issue Sep 16, 2019 · 10 comments
Closed

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

nimabrownlee opened this issue Sep 16, 2019 · 10 comments

Comments

@nimabrownlee
Copy link

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?

@davestewart
Copy link
Owner

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?

@nimabrownlee
Copy link
Author

@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.

@davestewart
Copy link
Owner

davestewart commented Sep 17, 2019

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.

@nimabrownlee
Copy link
Author

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.

@davestewart
Copy link
Owner

davestewart commented Sep 17, 2019

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

@nimabrownlee
Copy link
Author

@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.

@davestewart
Copy link
Owner

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.

@nimabrownlee
Copy link
Author

@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...

@davestewart
Copy link
Owner

davestewart commented Sep 18, 2019

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

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