0

I'm creating a REST API from scratch for a preexisting iOS app whose API source code is, for all intents and purposes, no longer available. This means I'm analyzing how each endpoint expects requests sent to it to be formatted. One of those endpoints is communicated with via Alamofire's Session.upload(multipartFormData:to:method:headers:).

The multipartFormData is a closure parameter that is passed a MultipartFormData object, permits the consumer to mutate it (add key-value pairs to it in this case), and then return it from the closure.

My question is how does that addition of these key-value pairs to the MultipartFormData affect the format of the HTTP request. Up until this point every .post method has been passed a Dictionary<String, Any> and JSON has been specified as the encoding, so it has been straightforward to assess how the payload is uploaded (a single JSON object with a parameter for each entry in the dictionary). But it is not so straightforward with this Session.upload(multipartFormData:to:method:headers:) method. I essentially want to know how the key-value pairs are encoded into the request so I know how to decode them server side.

shoe
  • 952
  • 1
  • 20
  • 44
  • You do it. In the closure `multipartFormData`, you append yourself the `Data` giving you "logic", which is usually the same. Look at sample to get an idea. – Larme Nov 17 '21 at 06:52
  • Seeing the code of https://github.com/Alamofire/Alamofire/blob/a41c07a558b508bcf3a66552c726cab5dda65501/Source/MultipartFormData.swift you'll see that the `append()` (and its various variations) will add at the end, the boundaries etc needed. – Larme Nov 17 '21 at 07:01

0 Answers0