Skip to content

VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps.

License

Notifications You must be signed in to change notification settings

vafreitas-zz/VFNetwork

Repository files navigation

GitHub Light GitHub Dark

Build Version SPM License Platform

Simple, Fast and Easy.

Introduction

VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps.

How to use

Basically, you need two files to assemble your requests and put Base_URL, Protocol and Environment in your info.plist.

Info.plist

Yout Plist

You have 3 types of Environments for you choose.

enum EnvironmentCase: String {
    case production = "production"
    case sandbox = "sandbox"
    case mock = "mock"
}

HomeAPI.swift

Here you will configure your requests.

import VFNetwork

enum HomeAPI {
    case joke
    case categories
}

extension HomeAPI: APIBuilder {
    
    var path: URLPath {
        switch self {
        case .joke:
            return .plain("jokes/random")
        case .categories:
            return .plain("jokes/categories")
        }
    }
    
    var httpMethod: HTTPMethods {
        switch self {
        case .joke, .categories:
            return .get
        }
    }
    
    var headers: HTTPHeader {
        .custom([
            .bearer("yourToken"),
            .basic("yourBase64"),
            .header("custom", "header")
        ])
    }
    
    var task: HTTPTask {
        switch self {
        case .joke, .categories:
            return .request
        }
    }
    

HomeService.swift

And here you will execute your requests.

import VFNetwork

class HomeService: RequestService<HomeAPI> {
    func getJoke(completion: @escaping (Result<JokeModel, Error>) -> Void) {
        execute(.joke, responseType: JokeModel.self, completion: completion)
    }
    
    func getCategories(completion: @escaping (Result<CategoryModel, Error>) -> Void) {
        execute(.categories, responseType: CategoryModel.self, completion: completion)
    }
}

That's it. enjoy...

Documentation

All documentation can be found in our Site including detailed api instructions and more.

Requirements

Installation

VFNetwork is available through CocoaPods. To install it, simply add to your Podfile:

target 'YourApp' do
  use_frameworks!

  # Pods for YourApp

  pod 'VFNetwork'

end

Author

Victor Freitas | iOS Developer

License

VFNetwork is available under the MIT license. See the LICENSE file for more info.

About

VFNetwork is a protocol-oriented network layer that will help you assemble your requests in just a few steps.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published