-4

This is the curl.

curl -X GET \
-H "X-Parse-Application-Id: XXXX" \
-H "X-Parse-REST-API-Key: XXXX" \
-G \
--data-urlencode "where={\"Area\":\"Vesu\"}" \
https://parseapi.back4app.com/classes/RESTAURANT

How to send GET request with where type of parameters through URLSession?

1 Answers1

0

You need to encode the query string, then create a URLRequest with the headers and the URL containing your baseURL and the query. Lastly, you need to call the dataTask to execute your request.

let baseUrl = "https://parseapi.back4app.com/classes/RESTAURANT"
guard let queryParameters = "where={\"Area\":\"Vesu\"}".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return}
guard let url = URL(string: baseUrl+"?"+queryParameters) else {return}
var urlRequest = URLRequest(url: url)
urlRequest.allHTTPHeaderFields = ["X-Parse-Application-Id":"XXXX", "X-Parse-REST-API-Key":"XXXX"]
URLSession.shared.dataTask(with: urlRequest, completionHandler: { data, response, error in
    guard error == nil else {
        print(error!); return
    }
    //handle data and/or response
}).resume()
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116