|
|
|
|
@ -129,6 +129,10 @@ public class Services { |
|
|
|
|
return try self._baseRequest(servicePath: servicePath, method: .post) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _putRequest(servicePath: String) throws -> URLRequest { |
|
|
|
|
return try self._baseRequest(servicePath: servicePath, method: .put) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _getRequest(servicePath: String) throws -> URLRequest { |
|
|
|
|
return try self._baseRequest(servicePath: servicePath, method: .get) |
|
|
|
|
} |
|
|
|
|
@ -161,7 +165,13 @@ public class Services { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func post<T: Storable>(_ instance: T) async throws -> T { |
|
|
|
|
var postRequest = try self._postRequest(servicePath: T.resourceName()) |
|
|
|
|
var postRequest = try self._postRequest(servicePath: T.resourceName() + "/") |
|
|
|
|
postRequest.httpBody = try jsonEncoder.encode(instance) |
|
|
|
|
return try await self._runRequest(postRequest) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func put<T: Storable>(_ instance: T) async throws -> T { |
|
|
|
|
var postRequest = try self._putRequest(servicePath: T.resourceName() + "/" + instance.id + "/") |
|
|
|
|
postRequest.httpBody = try jsonEncoder.encode(instance) |
|
|
|
|
return try await self._runRequest(postRequest) |
|
|
|
|
} |
|
|
|
|
|