Questions tagged [server-side-swift]

79 questions
8
votes
2 answers

Vapor 3 - send a HTTPRequest

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:…
rustyMagnet
  • 3,479
  • 1
  • 31
  • 41
8
votes
3 answers

Swift equivalent of Ruby's "Pathname.relative_path_from"

Ruby's Pathname.relative_path_from documentation. In objc there is already KSFileUtilities' ks_stringRelativeToURL method, that is very close. I'm looking for a pure swift solution that can run on Linux. I prefer a solution uses file:// URL's, but…
neoneye
  • 50,398
  • 25
  • 166
  • 151
8
votes
2 answers

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

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?
Joe Huang
  • 6,296
  • 7
  • 48
  • 81
6
votes
2 answers

Running actions after file stream in Vapor 4

I run a website that handles large files (uploads and downloads). Currently I am transitioning the site from Perfect to Vapor. In Perfect, it is relatively simple to stream a file to users, and then perform some actions AFTER the file is done. I am…
MAH
  • 841
  • 6
  • 16
6
votes
1 answer

Detecting a client disconnecting with UDP using Network.framework

I'm trying to determine when a UDP client stops sending packets to a server when using Network.framework I've built out a small example which demonstrates the server failing to change states to .cancelled when a client's connection is…
Emma K Alexandra
  • 464
  • 3
  • 15
6
votes
1 answer

Returning redirect response instead of expected leaf view

I have a route handler which returns a Future for my login page, defined as follows : func boot(router: Router) throws { let authSessionRoutes = router.grouped(User.authSessionsMiddleware()) authSessionRoutes.get("/login", use:…
user2700551
  • 339
  • 2
  • 6
  • 24
5
votes
2 answers

Server Side Swift: Navbar Toggle not working in Vapor 4 Leaf + Bootstrap

Configurations: Vapor 4 | Updated beta version & packages | macOS Catalina v.10.15.3 | XCode 11.4 beta 2 | Bootstrap CDN 4.4.1 I'm unable to toggle my navbar button. I'm not sure if it's a bug in Leaf. I've implemented Bootstrap and CSS in the right…
5
votes
1 answer

Using vapor-fluent to upsert models

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:…
dehlen
  • 7,325
  • 4
  • 43
  • 71
5
votes
1 answer

Add Column to Existing Table in Vapor

I have a project that I am working on that has Posts and Comments. I link a comment to a post using a foreign key (postId). However, this foreign key was not added to my Comment class until after the first time I had built the project with the…
BlondeSwan
  • 772
  • 5
  • 26
5
votes
1 answer

Server Side Swift: basic Client-Server communication example for iOS and Android

Learning a new technology is a time consuming process. It was for Android with Java. And it was again for iOS with Swift. I'm now faced with the challenge of needing to provide a server backend for both Android and iOS apps. However, I would like to…
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
4
votes
2 answers

How to pass parameters in request while routing (Server Side Swift using Vapor)

I'm writing a web service using Vapor framework in Swift. In my app, I have User model. The following is how I route a get request for all users. router.get("users") { request in return User.query(on: request).all() } After running the server…
imthath
  • 1,353
  • 1
  • 13
  • 35
4
votes
1 answer

Does Swift executable binary need the .swiftmodule, .swiftdoc and .build files to run?

I'm writing my Swift app for Ubuntu using Vapor. And my mission is to have the smallest Docker image for production. I've trimmed down my image significantly but I wanted to know, just out of curiosity, does my final executable need all the compiled…
Andrew Edwards
  • 1,005
  • 1
  • 9
  • 24
4
votes
1 answer

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

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…
Chris Prince
  • 7,288
  • 2
  • 48
  • 66
4
votes
3 answers

Swift Package Manager and Xcode: Retaining Xcode Settings?

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…
Chris Prince
  • 7,288
  • 2
  • 48
  • 66
4
votes
2 answers

Test-only Dependencies When Using the Swift Package Manager

I've seen mentions of test-only dependencies when using the Swift package manager but haven't been able to get them to work. For…
Chris Prince
  • 7,288
  • 2
  • 48
  • 66
1
2 3 4 5 6