Skip to content

Commit 71b2716

Browse files
committed
Update URLSessionExtension.swift
1 parent 890ed07 commit 71b2716

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/SwiftBoost/Foundation/Extensions/URLSessionExtension.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public extension URLSession {
5555
static func request(
5656
url: String,
5757
method: HTTPMethod,
58-
body: [String: Any]? = nil,
58+
body: [String: Any?]? = nil,
5959
contentTypeHeader: ContentType? = nil,
60-
completion: @escaping (AppError?, Data?, HTTPURLResponse?) ->Void)
61-
{
60+
completion: @escaping (AppError?, Data?, HTTPURLResponse?) -> Void
61+
) {
6262
guard let url = URL(string: url) else {
6363
completion(AppError.invalidURL(url), nil, nil)
6464
return
@@ -73,7 +73,10 @@ public extension URLSession {
7373
}
7474

7575
// Body
76-
if let body {
76+
if var body = body {
77+
78+
body = body.compactMapValues { $0 } // delete `nil` values
79+
7780
do {
7881
let jsonData = try JSONSerialization.data(withJSONObject: body, options: [])
7982
request.httpBody = jsonData

0 commit comments

Comments
 (0)