Server Side Swift with Vapor: Making a Web App | Ray Wenderlich

Learn how to make a simple web app to list, create, and delete objects using Vapor, a popular server side swift framework.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5003-server-side-swift-with-vapor-making-a-web-app

good one, as usual :+1:t3:

although, in the implementation of addAcronym (and deleteAcronym), I’d rather just return the value of a call to indexView instead of the redirect, so basically return indexView(request).

just a personal choice / opinion thing, I guess :wink:

Thank you @rwenderlich great tutorial,
it would be great if you can make an advanced course on Vapor .
Have a good one

YoelL

Awesome tutorials! Advanced course on Vapor would be incredibly beneficial. How to make it secure, advanced interaction with database and etc. Thank you so much!

@goranche Thanks! There is one advantage to using the redirect though (which I should have mentioned in the video)! :]

Imagine you don’t redirect, and return try indexView(request: request) instead. Then when you add an acronym, your browser is displaying the result of the POST to /til, and if you refresh the page, the browser effectively tries to re-post the same acronym (which isn’t desired; really the user probably just wants to refresh the latest list of acronyms). You get a warning like this:

Similarly, in the deleting an acronym case, the browser is displaying the result of a POST to /til/acronymId/delete:

And if you refreshed the browser, it would try and delete that acronym instead.

By redirecting to index, if you refresh the page it doesn’t try to re-add or delete anything. I hope that makes sense, and thanks for pointing this out as I’ll be sure to mention this if I ever cover this again! :]

@yoele @booorisss Thanks for your kind words and suggestions! :]

huh :thinking: hadn’t thought of that, but yes, you’re right :sweat_smile:

hope you didn’t waste too much time trying it out :relaxed:

Thanks for another tut, we’re building up a nice website now.

Thanks Ray. You are awesome. From Peru!!!

@alexhedley @keyner Thanks guys! :]

Another app made with vapor

http://www.nsregularexpression.com/

Code is on GitHub to see how it’s done

Cool, thanks for pointing this out @alexhedley!

How can we return different Response for different consumers in controller class, like I want to return below response for web-site

        return Response(redirect: "/v1/student")

and different response for mobile apps like below

        return try JSON(node: [
            "error" : false,
            "message" : "Student added successfully"
            ])

I am not getting how to achieve this.

Hi, did anyone come across this error when playing the video “The media could not be loaded, either because the server or network failed or because the format is not supported.”? I tried both Chrome and Safari.

@chwang I just tried and it’s loading OK for me, and haven’t heard of anyone else w/ issues. Maybe check your connection?

@rwenderlich you are right, it was my connection issue, thanks!

@rwenderlich
Great series. Can we possibly organize the videos into a playlist so we can follow them in the right order.

1 Like