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

amro-baira23's avatar

is it a good practice in general to return a formdata object back to the client in a rest api?

I'm trying to let users download files for github like pet project i'm trying to build but i want to add some other key-value data with those files just like how clients send formdata to the servers but i don't know if thats a good idea to begin with. What other alternatives can i consider?

0 likes
3 replies
vincent15000's avatar

A formdata is to send data from a client to the backend via an HTTP client like for example axios.

A formdata is typically in JavaScript, I can't imagine how you could create a formdata in a Laravel controller and send it back to the client.

1 like
amro-baira23's avatar

@vincent15000 well, i have seen some implementaitons of formdata objects in other langauges like dart where clients sends formdata/multipart to server so i assumed that would be applicable in php as well.

What to the right way to do the thing that I'm trying to do in your opinion?

thanks very much for your speedy reply

1 like
vincent15000's avatar

@amro-baira23 I don't know dart, but it seems to be a frontend languague and as you say, dart can send formdata from clients to server and not from server to clients.

If you need to pass data from the server to the client, just send JSON datas.

Please or to participate in this conversation.