Sponse() in XML with Laravel

Asked

Viewed 1,263 times

1

I have studied about developing Apis with Laravel, a quick question, it is possible to return an XML instead of a json?

instead of doing:

return response()->json($json);

do something like:

return response()->xml($xml);

I searched for XML in the documentation and did not find...

  • is not the answer to your question but... why do you want to return XML? JSON is much better in many ways, mainly because it is much easier to serialize or deserialize...

  • the answer is your kkkk question, XML is already more complicated and to complete mine is signed, if I serialize or deserializar, the signature will become invalid. I need to get past him without making any modifications.

  • What I’m doing at the moment is taking this XML via FTP, but for an API this is complicated because I have to create an FTP account for each application that consumes the API...

  • this XML comes from some directory on the machine that is running or it is in memory?

  • it gets in memory soon after it is saved on machine, I would like to send before being saved.

2 answers

1

There is nothing related to XML in specific, but found that document which speaks of file download. But for this you need to download it on the machine before sending it.

return response()->download($pathToFile); 

return response()->download($pathToFile, $name, $headers);

return response()->download($pathToFile)->deleteFileAfterSend(true);

$pathToFile is the directory where you saved your XML. You can use 3 types of parameters.

  • The first you pass only the file path.

  • The second you way, name and the headers

  • The third you pass the path and specifies whether or not to delete it after downloading.

  • 1

    Even though the previous solution is what I need, your answer gave me an idea of a solution within the Framework, I will do tests

  • @Jeffersoncarlosbd good ;)

  • @Jeffersoncarlosbd does not forget to mark his question as the correct ok ?

1


  • Seems to be what I need, I’m gonna run some tests

  • Hmmm, good, I believe that Flavio’s answer is the most correct, but I will keep mine because it is a different way to do what you wanted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.