Start a Project

Rest API calling using RxSwift.

Today, I am going to show how to call rest API using RxSwift. Before the start, we need to know some concept in RxSwift. RxSwift is the swift implementation of popular Reactive Extensions (Rx) library created by Microsoft.

What is Reactive programming?

Reactive programming is an declarative programming paradigm concerned with data streams and the propagation of change. This means that it becomes possible to express static (e.g. arrays) or dynamic (e.g. event emitters) data streams with ease via the employed programming language(s).

— https://en.wikipedia.org/wiki/Reactive_programming.

1. Observables: is like a function with some special characters.

2.Observer: Observables produce some result according to data or action. This Result is called the Observer.

For example: .subscribe(next, error, complete) 

Here subscribe is Observableandnext, error, complete are Observer.

3.DisposeBag: This is used to deinit() Observer objects from the memory.

Let start the implementation of RxSwift.

Step 1: Create a new project and pod file

Add RxSwift and RxCocoa in your pod file and install the pod.

 

Step 2: Creare a Model Class

 

Step 3: Create an API Request

Create an enum for request type which is helping to manage the API request Type.

 

Create a class for API Request

 

Configure the API request.

Now calling API.

Step 4: Create an APICalling class and DisposeBag object.

 

Load TableView after API call.

I hope it will help everyone.

 

Exit mobile version