How to add a vapor api to swift project

I am curious. There are videos where we are taught to create a backend vapor project, but what do we do after that? How do we implement that backend into an iOS app?
Thank you

@samgusaapp1993 Thanks very much for your question!

One of the purposes of doing back end development is to connect to a web service to download data for your app. REST API’s are one of the most common types of web services that apps today connect to in order to provide data to the user. Thus, one of the benefits of learning back end development with Swift using a framework like Vapor is perhaps to build your own API to store data in the cloud, which your can then connect to, and receive data, as well as upload data back to the service :slight_smile:

I hope this helps!

All the best!

@samgusaapp1993,
In addition to what @syedfa responded, I would like to add,

Till now if you had a backend you would use languages like PHP, ASP.NET, JC (Node.JS) etc to create the backends and then consume these services in an iOS App. Facebook for example is a backend that serves information which is consumed on an iOS front end. With frameworks like Kitura, Vapor, Zweo, etc you can write these backends using swift. The idea is to manage everything in a single language - Swift, write the backend and the front end in Swift. Hope that helps you understand this in a different context.

Cheers,

Jayant

Hello,
Thank you for the understanding. if i may ask another question, How do i use the vapor api that i have created to interact with an iOS app?
For example: if i had a vapor backend that is using mysql database. In that database there are famous names and difference sentences from those famous people stored in the database and i wanted to make an iOS app that has a tableview that shows those famous people’s names and when a name in that table is clicked it goes to a new page and shows the quote from that famous person. How would i go about that doing that. I have a vapor backend and i tested it in postman, everything works fine, i just don’t know how to use it in an app.
Thank you for your help
Sam

Hi @samgusaapp1993! I understand you would like to use your vapor api with an iOS app. To help you get started, I would watch this useful video if you have’t already! Also, Vapor has a great learning reference here, Vapor University that also provides some Ray Wenderlich videos. Again, if you are not familiar with using Vapor and Swift, I highly recommend watching these great video tutorials. If you are also new to Swift, this tutorial here helps you with presenting data from an API to a tableview, something I think you wanted to do correct? Hope this helps you on your Vapor and Swift project. Happy Coding!

Gina

hello Ms. Gina,
thank you for your help, but where are the videos?
Sorry,
Sam

Hi @samgusaapp1993, sorry about that! Links are here:
https://videos.raywenderlich.com/screencasts/509-server-side-swift-with-vapor-getting-started

Best,
Gina

Hi Gina, I have been searching for the same answers for the past 4 months, the videos do not address connecting an iOS app to a Vapor api, that information does not seem to exist anywhere on the web nor have I ever seen any references stating such capability. I assume it’s possible but curious why it has never been addressed anywhere.

Ok, why didn’t anyone here mention URLSession? Well at least it’s one step closer.

i would try alamofire and swiftyjson. There are many tutorials about using both to access an API.

Feel like I should probably add to this, especially as my Vapor course is now up! In most tutorials, you’ll use Postman or Rested to connect to your Vapor API - the iOS app is exactly the same! You can use URLSession or Alamofire to perform the same GET/POST/DELETE etc requests as those REST clients have.

Unfortunately there wasn’t time in the videos to go through connecting up a simple iOS app but there will be a chapter dedicated to it in the upcoming book (which I’m co-authoring with the Vapor team). Feel free to ask me any questions!

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.