D
D
Dmitry2017-02-02 23:56:28
Yii
Dmitry, 2017-02-02 23:56:28

Return server response in xml, what to use?

Goodnight.
Tell me how to solve the problem correctly?
There is a table in a DB where the data on flights is stored.
You need to make something like an api for the site.
The user should send a get request to the site in the form of a string like this:

http://example.ru/api/search?from=MOW&to=LED&date1=2012-09-25&date2=2012-10-01&adults=2&children=1&infants=1&cabin=Y&partner=avsl&password=pass

In the get parameters, the city of departure / arrival, the date of departure / arrival, the number of passengers, class (economy, business), carrier code and password are passed. In response, you should receive data in xml format + a link to this data, which will lead to the ticket ordering form.
I am reading articles for the second day and I can’t decide what to use to implement this task on YII2 ?
RESTful api or just yii2 class yii\web\Response .
I do not need authorization and verification of access rights, the data is public.
It only takes two actions:
1) Return the search result
2) Submit the order form
Now I have implemented this using yii\web\Responsebut I'm wondering if this is the correct approach or not?
What do you advise?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-02-03
@slo_nik

you need to understand that RestApi is not just a get request and an xml / json response, it is a specific specification for the Api structure. Ask yourself the question - does your site need to support this specification? if yes - implement RestApi based on Yii tools, if not - work with Response.

M
melnikov_m, 2017-02-03
@melnikov_m

You can upgrade to yii 2.0.11. Two methods have been added to the controller: asJson() and asXml(). They serve to return data in JSON and XML format, respectively.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question