Skip to content

A simple class that makes REST API requests and mock these datas automatically (if you wanna).

License

Notifications You must be signed in to change notification settings

AlbertoLourenco/URLMockSession

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URLMockSession

A simple class that makes REST API requests and mock these datas automatically (if you wanna).

If you don't want to use larger libraries than will takes up large spaces on your project, add this class and make all of your REST API requests and mock these datas when you need this.

With URLMockSession you can load local mocked datas without hard work.

Why use this class?

  • Shortly code;
  • Simple application;
  • Works with threads;
  • Mock your API responses;
  • Easily switch to load mock or REST API data;
  • This class takes up less space (only 14kb);

How to use

First set all of your configs to apply URLMockSession basic informations:

var config = MockConfig()
        
config.baseURL = "https://viacep.com.br/ws/"
config.timeout = 60
config.headers = []
config.token = ""
config.mock = true
config.testingFail = false
config.testingSuccess = false

Requesting REST API

After complete class configs, make your REST API request:

let manager = URLMockSession(with: config)
manager.request(method: .get,
                endpoint: "01001000/json/",
                parameters: [:],
                authenticated: false,
                responseType: Dictionary<String, String>.self) { (response, code) in
                    print(String(describing: response))
                }

Getting all mocked data

If you want to see all mocked data, implement this script:

let mocks = MockManager.shared.all() // Array<Mock>
for item in mocks {
    print(item.endpoint)
}

Requirements

- iOS 10+
- Swift 5
- Xcode 10

This project uses:

- UIKit
- Decodable
- URLSession
- FileManager
- UserDefaults

Using extensions:

- Date
- Dictionary
- URLResponse

About

A simple class that makes REST API requests and mock these datas automatically (if you wanna).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages