Reusable APIManager — Using Alamofire and EvReflection for IOS Applications in Swift

Seyhun AKYÜREK
Seyhun Akyurek
Published in
2 min readFeb 9, 2017

I was using different types of Managers for the projects I’ve worked on. Because separating operations much as possible have good benefits to make application reusable and manageable.

In this post, I’ll share my APIManager used in projects I’m worked before. It is a singleton class to manage different types of API requests so implementation would be easy and reusable.

Setting up

First, we need mapping models for our request and response classes to use the Service. So, in APIManager are using models to handle networking request/response operations. You can find the detail in here.

Also, I was used the RouterManager for the APIManager, you can find in here.

APIManager used another managers to handle different requirements i.e AlertManager to handle error alert popups and ErrorManager to handle error actions etc. So, in this post, I omitted details about them. I’ll share them in next posts.

Steps

  • Setup an APIManager in your /managers folder.
  • Setup your API methods, methods take request/response classes as arguments and handles routing using RouterManager class for handling operations (.GET, .POST etc.)

Manager

Implementation

  • In your ViewModel, Presenter etc. you can call APIManager’s methods for (i.e .getLogin, .postLogin) etc.

So, the response would be handled by APIManager, you can do your own tasks in completion. (i.e setting LoggedInState to .loggedIn or redirecting to another scene etc.)

Thanks for the reading.

About the Author

Here is my website, portfolio, and works. 👨‍💻

Follow me on Github

Follow me on Twitter.

--

--

Seyhun AKYÜREK
Seyhun Akyurek

Application Team Leader Mobile Channels in Commercial Bank Of Dubai. Enterprise Design Thinking Co-Creator/Practitioner, Blogger