Question: I am currently working on fetching flight information/data using Google's QPX Express. The platform I am using is Swift. I have taken the following steps

I am currently working on fetching flight information/data using Google's QPX Express. The platform I am using is Swift.

I have taken the following steps below: 1. Create a request body per googles API requirement(Only require parameters, no optional ones) https://developers.google.com/qpx-express/v1/trips/search 2. I converted the request body into a JSON data format 3. I created A request with the JSON data as the body and a Content-Type: application/json 4. I ran using URLSession and keep receiving a 400 status code

I am currently working on fetching flight information/data using Google's QPX Express.

//create format to replicate QPX Express requirement let passenger Dict "passengers "kind "qpxexpress#passengerCounts", adult Count 1]] let slice Dict slice kind "qpxexpressatisliceInput", "origin": NYC destination LAX date 2017-05-05" let requestDict "request": [passengerDict, sliceDict]] //convert from Dictionary to Data let data try JSON Serialization. data with ject requestDict, options: CJ) Create URL let url URL init(string https://www.googleapis.com/qpxExpress/v1/trips/search? key AIzasyDQQBQ2yff JTBHR HVXsbe00DIwEwdUITJQ") Create Request var request URL Request.init(url: url!) request httpMethod POST request httpBody data request addValue "application/json fo rHTTP Field Content-Type") Header //request .addValue application/json forHTTPHeaderField: Accept") Create Session & Run let config URLSession Configuration default let task URL Session init(configuration config) .dataTask(with: request) (data, response, error) in let esponse esponse as HTTPURLResponse print (response status Code) print (response task resume

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!