-2

I am testing a GET request using Postman. In Params tab, there is Path Variable with an "id" key and a value. You can see the URL of GET request in this screenshot below, there is url path /:id in the end of the URL endpoint.

enter image description here

How to perform GET request with Path Variables params as such in Swift?

Thanks

2 Answers2

2

In Params tab, there is 'Path Variable' with an "id" key and a value

This means you can replace this :/id with your actual id value in url.

func getRequestAPICall()  {

        let apiUrl : String = "your_server_url" + "/" + "yourIdValueHere"

        Alamofire.request(apiUrl, method: .get, encoding: JSONEncoding.default)
            .responseJSON { response in
                print(response)
            }
    }
Keshu R.
  • 5,045
  • 1
  • 18
  • 38
-1

Simple Request using URLSession

func getAPDemo(url:URL){

        var request = URLRequest(url: url)
        request.httpMethod = "GET"

        let task = URLSession.shared.dataTask(with: request) { (data, response, error) in


             // handle data , error here according to need
        }
        task.resume()

  }
Vasucd
  • 357
  • 2
  • 10