server-side-swift

How do I download a file and send a file using Vapor server side swift?

烂漫一生 提交于 2020-02-28 08:08:27
问题 How do I download a file using server side swift? I have tried this: let result = try drop.client.get("http://dropcanvas.com/ir4ok/1") but result.body always = 0 elements How do I send a file? I have tried this drop.get("theFile") { request in let file = NSData(contentsOf: "/Users/bob.zip") return file // This fails here } 回答1: Download a file. You are on the right track here, but the reason why result.body is always empty is because your file service is returning a 302 redirection rather

Vapor 3 - send a HTTPRequest

喜夏-厌秋 提交于 2020-01-02 02:41:14
问题 How do you send an API request in Vapor 3 with the HTTPRequest struct? I tried variations of the following code.. var headers: HTTPHeaders = .init() let body = HTTPBody(string: a) let httpReq = HTTPRequest( method: .POST, url: URL(string: "/post")!, headers: headers, body: body) let httpRes: EventLoopFuture<HTTPResponse> = HTTPClient.connect(hostname: "httpbin.org", on: req).map(to: HTTPResponse.self) { client in return client.send(httpReq) } The compile error Cannot convert value of type '

Numeric types don't automatically bridge to NSNumber in pure Swift on Ubuntu Linux?

佐手、 提交于 2019-12-21 19:41:50
问题 On MacOS, if you do: import Foundation let x = Int32(1) as? NSNumber x is non-nil. On Ubuntu Linux, if you do the same (even with Swift 3.1.1), x is nil. Am I doing something wrong, or is this just a fact of a lack of bridging of numeric types to NSNumber with the Foundation with Swift on Ubuntu/Linux? See also Is it possible to replicate Swifts automatic numeric value bridging to Foundation (NSNumber) for (U)Int8/16/32/64 types? and https://github.com/SwiftyJSON/SwiftyJSON/issues/745 回答1:

How to use timer in Vapor (server-side Swift)?

梦想与她 提交于 2019-12-19 07:18:08
问题 Can I use timer, such as NSTimer in Vapor (server-side Swift)? I hope my server written in Vapor can do some tasks proactively once in a while. For example, polling some data from the web every 15 mins. How to achieve this with Vapor? 回答1: If you can accept your task timer being re-set whenever the server instance is recreated, and you only have one server instance, then you should consider the excellent Jobs library. If you need your task to run exactly at the same time regardless of the

Swift Package Manager and Xcode: Retaining Xcode Settings?

落爺英雄遲暮 提交于 2019-12-10 16:48:43
问题 I am developing a server in Swift and using the Swift Package Manager. And find it convenient when doing my development on my Mac OS system to generate a Xcode project to use Xcode as my IDE (i.e., From time to time, my package dependencies have to be updated. I've been using swift package generate-xcodeproj to do this. My problem comes in at this point-- I have created some settings in Xcode. E.g., I've set a DEBUG flag, and I have a .plist file that is in the Copy Files Phase. These get

Using vapor-fluent to upsert models

左心房为你撑大大i 提交于 2019-12-06 06:27:40
问题 I am currently struggling with doing an upsert with vapor/fluent. I have a model something like this: struct DeviceToken: PostgreSQLModel { var id: Int? var token: String var updatedAt: Date = Date() init(id: Int? = nil, token: String, updatedAt: Date = Date()) { self.id = id self.token = token self.updatedAt = updatedAt } } struct Account: PostgreSQLModel { var id: Int? let username: String let service: String ... let deviceTokenId: DeviceToken.ID init(id: Int? = nil, service: String,

Using vapor-fluent to upsert models

点点圈 提交于 2019-12-04 14:39:22
I am currently struggling with doing an upsert with vapor/fluent. I have a model something like this: struct DeviceToken: PostgreSQLModel { var id: Int? var token: String var updatedAt: Date = Date() init(id: Int? = nil, token: String, updatedAt: Date = Date()) { self.id = id self.token = token self.updatedAt = updatedAt } } struct Account: PostgreSQLModel { var id: Int? let username: String let service: String ... let deviceTokenId: DeviceToken.ID init(id: Int? = nil, service: String, username: String, ..., deviceTokenId: DeviceToken.ID) { self.id = id self.username = username .... self

How to use timer in Vapor (server-side Swift)?

北城以北 提交于 2019-12-01 05:22:12
Can I use timer, such as NSTimer in Vapor (server-side Swift)? I hope my server written in Vapor can do some tasks proactively once in a while. For example, polling some data from the web every 15 mins. How to achieve this with Vapor? If you can accept your task timer being re-set whenever the server instance is recreated, and you only have one server instance, then you should consider the excellent Jobs library. If you need your task to run exactly at the same time regardless of the server process, then use cron or similar to schedule a Command . Kerusan If you just need a simple timer to be