Git Product home page Git Product logo

emdpoint's Introduction

Emdpoint

This library is a tool for handling different types of HTTP requests in a convenient way.

Document


Constents


Requirements

  • iOS 13.0+ / tvOS 13.0+ / macOS 10.15+ / watchOS 7.0+
  • Swift 5.4+

Overview

Emdpoint is a library that provides a convenient way to handle HTTP requests.


Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate Emdpoint into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/GSM-MSG/Emdpoint.git", .upToNextMajor(from: "1.0.0"))
]

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate MSGLayout into your project manually.


Usage

Quick Start

import Emdpoint

enum JsonEndpoint {
    case todos
}

extension JsonEndpoint: EndpointType {
    var baseURL: URL {
        URL(string: "https://jsonplaceholder.typicode.com/")!
    }
    
    var route: Route {
        .get("todos")
    }
    
    var task: HTTPTask {
        .requestPlain
    }
}

import Combine
import UIKit

final class ViewController: UIViewController {
    var bag = Set<AnyCancellable>()
    override func viewDidLoad() {
        super.viewDidLoad()
        let client = EmdpointClient<TestEndpoint>()

        // MARK: - Async/Await
        Task {
            let data = try await client.request(.todos).data
            let prettyData = try? JSONSerialization.jsonObject(with: data)
            print(prettyData)
        }

        // MARK: - Combine
        client.requestPublisher(.todos)
            .sink { completion in
                switch completion {
                case .finished:
                    print("finished")
                case .failure(let error):
                    print(error)
                }
            } receiveValue: { data in
                print(data)
            }
            .store(in: &bag)

        // MARK: - Completion Closure
        client.request(.todos) { result in
            switch result {
            case .success(let data):
                print(data)

            case .failure(let error):
                print(error)
            }
        }
    }
}

emdpoint's People

Contributors

baekteun avatar

Stargazers

이강현 avatar  avatar  avatar

emdpoint's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.