Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eins's avatar
Level 1

Best way to perform an API operation

Hey guys,

I have a really simple question for the best practice to add this operation or you can call it whatever you want. Let's say I have a couple of steps (also different pages/controllers) to register a user, in the first step the user must indicates some info and the important part is checking if he would like to subscribe to the news letter. If he choose yes, then i should send to an API the info's about the user.

So my question is : What is the best way to do this ? inside the controller that handle first step inside the store method ? create a separate file to perform this ?

Thank you.

0 likes
4 replies
automica's avatar

you should have an endpoint to accept the details of your user.

you'll want to post to this, validate and save the user's details, then return 200 or 201 back as a response.

if you then need to any tasks relating to signup you'd be best to trigger an event within your controller to do this, and that event can handle calling the external api.

1 like
eins's avatar
Level 1

@automica Thank you for taking the time to answer me. I was thinking about the same thing but i admit that i have no clue to do this, i just don't want to write my code inside the controller that store info's, i would like to do it in a separate file ( may need more function for that same API ) and then invoke the function but i don't know why, it's been a while that i didn't practice Laravel.

martinbean's avatar

@eins You should dispatch a queue job that does the API call, because if the API is down or running slowly, then that’s going to affect your app, which you don’t want.

1 like
eins's avatar
Level 1

@martinbean Thank you @martinbean for your response, actually i wanted to do that but wasn't sure if it is a good idea since i don't have a really good idea of how to use Jobs. But i will take a deeper look it should be the best way to solve my doubts.

Please or to participate in this conversation.