Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
//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 resumeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started