Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST request only json string #6

Open
sergvax opened this issue Sep 11, 2020 · 1 comment
Open

POST request only json string #6

sergvax opened this issue Sep 11, 2020 · 1 comment
Labels
question Further information is requested

Comments

@sergvax
Copy link

sergvax commented Sep 11, 2020

As I understand - POST request only possible with json string -
is it true?

Can you make POST request with any string(example - dataForm)?
Can you give example how to make POST request?

Can you explain this part of swift code -
if (method.rawValue == "POST" || method.rawValue == "PUT"){
request.httpBody = try? JSONSerialization.data(withJSONObject: params, options: [])

@WyattMufson
Copy link
Member

WyattMufson commented Sep 11, 2020

The request object for POST is expecting a Data type (see here). NetworkUtills is a wrapper built around the Foundation URL Loading System to make it easier to pass in data. NetworkUtils is expecting a JSON style object ([String: Any]) to be passed in.

If you take a look at this line you will see the arguments it's expecting.

Here is an example of how to use it:

let jsonDict: [String: Any] = ["key1": "val1", "key2": 2]
networkUtils.post("https://www.myapi.com/endpoint", jsonDict).then { (data) in
  // Data response from server
}.catch { (error) in
  // Error response
}

@WyattMufson WyattMufson added the question Further information is requested label Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants