How Make Request Body for Put Request in Swift

Viewed 67

How would I turn this request body below into a put request call with Alamofire?

{
  "context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
  "offset": {
    "position": 5
  },
  "position_ms": 0
}

It currently looks like this,

let parameters: [String: Any] = [
        "request": [
                "context_uri" : "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
                "offset" : "",
                "position_ms": 0
        ]
    ]

But it doesnt seem to be working.

1 Answers

For this endpoint it would be

let parameters: [String: Any] = [
    "context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
    "offset": [
        "position": 5
    ],
    "position_ms": 0
]

And make sure to use JSON encoding.

Related