TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Vapor Server Side Book : twostraws template

Forums > Books

Hi, i am starting the reading of the book and we are supposed to create a new vapore with this line in terminal : vapor new project1 --template=twostraws/vapor-clean

I got an error message saying : Error: Too many arguments: --template=twostraws/vapor-clean Is it because it is vapor 4 now? Anybody got any clue about this?

Thank you

3      

It seems like you're encountering an issue when trying to create a new Vapor project using the vapor new command with the --template=twostraws/vapor-clean option. The error you're seeing could be due to a few different reasons:

Command Syntax: Make sure you're using the correct syntax for the vapor new command. It should be in the format: vapor new <project-name> --template=twostraws/vapor-clean.

Vapor Version: As you mentioned, the issue might be related to Vapor 4. The template you're trying to use might not be compatible with Vapor 4 if it was designed for an earlier version. Check if there's an updated template available for Vapor 4.

Installation Issues: Ensure that Vapor is installed correctly on your system and is up-to-date. You can update Vapor using the following command: brew upgrade vapor/tap/vapor.

Template Availability: Confirm that the twostraws/vapor-clean template is still available and accessible from the repository. Templates might change or be removed over time.

To troubleshoot:

Double-check the command syntax, ensuring there are no typos or missing elements. Verify if there's an updated version of the template that's compatible with Vapor 4. Make sure your Vapor installation is up-to-date. Consider exploring other templates if the issue persists. If you can't find a suitable solution, consider checking the official Vapor documentation or community forums for assistance. Issues like this might also be reported and discussed by other users, helping you find a solution.

3      

Thank you very much for your answer @Aria_Dreamer It seems that the problem is Vapor 4. The template is the one in the book and i have not seen any update from Paul with this book. Maybe it is something coming. I'll be patient and will learn this stuff another time. I will continue you create my API with php until this is cleared. Thank you for your answer.

3      

@Aria_Dreamer clearly is a chat bot, as evidenced by the advice being so general and vague.

If you visit the Vapor discussion forum on Swift.org, you'll see the postings are very sparse. I deduce from this that Vapor's adoption rate is too low to make learning it a worthwhile investment in career growth.

https://forums.swift.org/c/related-projects/vapor/30

3      

In early 2021 I briefly explored Vapor 4 and found some basic templates by Mads Odgaard and Valentin Knabel. Based on their tutorials, I devised the following as the minimum code to run Vapor 4 in MacOS 10.15 Catalina. (I did not explore Fluent or Leaf.)

main.swift (in Run folder):

import App
import Vapor
var env = try Environment.detect()
try LoggingSystem.bootstrap(from: &env)
let app = Application(env)
defer { app.shutdown() }
try configure(app)
try app.run()

configure.swift (in App folder):

import Vapor
public func configure(_ app: Application) throws {
    // uncomment to serve files from /Public folder
    // app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))

    // register routes
    try routes(app)
}

routes.swift (in App folder):

import Vapor
func routes(_ app: Application) throws {
    app.get { req in
        return "It works!"
    }

    app.get("hello") { req -> String in
        return "Hello, world!"
    }
}

Package.swift:

// swift-tools-version:5.2
import PackageDescription

let package = Package(
    name: "VaporSimplest",
    platforms: [
       .macOS(.v10_15)
    ],
    products: [
        .library(name: "App", targets: ["App"]), 
        .executable(name: "Run", targets: ["Run"])
    ],
    dependencies: [
        // 💧 A server-side Swift web framework.
        .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
    ],
    targets: [
        .target(
            name: "App",
            dependencies: [
                .product(name: "Vapor", package: "vapor")
            ],
            swiftSettings: [
                // Enable better optimizations when building in Release configuration.
                // Despite the use of the `.unsafeFlags` construct required by SwiftPM,
                // this flag is recommended for Release builds.
                // Details at: <https://github.com/swift-server/guides#building-for-production>
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
        .target(name: "Run", dependencies: [.target(name: "App")]),
        .testTarget(name: "AppTests", dependencies: [
            .target(name: "App"),
            .product(name: "XCTVapor", package: "vapor"),
        ])
    ]
)

3      

Thank you for those elements.

In fact i went to Vapor because i would like to find a solution to access a mySql database i handle from SwiftUi applications i make. When i make a Java app i import the JDBC drivers in my app and i can access, update and morify the elements from my database.

It seems i can't have this simple with SwiftUi

3      

You might consider Django server for Python. Django natively supports MySQL stores (along with SQLite, Maria & Postgre).

On the djangoproject website, search for the "Databases" API reference page, then scroll down to the section discussing MySQL configuration.

4      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.