Skip to content

[IDLE-119] HTTP요청을 위해 네트워크 모듈 설계및 구현 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

J0onYEong
Copy link
Contributor

1. 관련된 이슈 및 소개

  • Service추상화

종류별로 API를 묶어내기 위해 BaseAPI로 API를 추상화 하였습니다.
구체 API타입을 Service에 전달하고 서비스의 요구사항과 합쳐저 구체 서비스 타입이됩니다.

class BaseNetworkService<T: BaseAPI> { ... }

protocol TestService {
    
    func testRequest() -> Single<[Person]>
}

class DefaultTestService: BaseNetworkService<TestAPI> { }

extension DefaultTestService: TestService {
    ...
}

해당 구조가 가지는 장점은 추상화된 API를 기점으로 서비스가 구체화 되어 특정 서비스에 사용될 API를 제한할 수 있습니다.

  • KeyValueStore

인증토큰들을 로컬에 저장하기위해 KeyValueStore로 저장소를 추상화하였습니다.
안정한 저장을 위해 KeyChain을 사용하기로 하였고 KeyChainAccess라이브러리를 사용하여 구체타입을 만들었습니다.

public protocol KeyValueStore {
    func save(key: String, value: String) throws
    func get(key: String) -> String?
    func delete(key: String) throws
    func removeAll() throws
}

extension KeyChainList: KeyValueStore {
    
    func save(key: String, value: String) throws {
        try keyChain.set(value, key: key)
    }
    
    func delete(key: String) throws {
        try keyChain.remove(key)
    }
    
    func removeAll() throws {
        try keyChain.removeAll()
    }
    
    func get(key: String) -> String? {
        try? keyChain.get(key)
    }
}

후에 다른 방법을 사용할 수도 있어 추상화하였습니다.

2. 변경된 점

NetworkInterface와 NetworkConcrete를 NetworkDataSoruce모듈로 합쳤습니다.
BaseAPI는 API베이스 주소같은 구체정보를 가지고 있는 추상타입입니다. BaseService역시 내부적으로 AF의 Adapter와 Retrier를 구현한 반 추상타입입니다. 모호한 타입들의 위치시키기 위해 새로운 모듈을 생성하기 보단 효율성을 위해 두 모듈을 합치는 방법을 선택했습니다.

4. 알게된 점

현재 DataSource에서 RxSwift를 사용하였습니다. Respository에도 사용될 것입니다. 이부분에서 도메인에도 효율성을 위해 RxSwift를 사용할 수 있지 않을까 생각하게 되었습니다. 해당 질문을 iOS멘토님께 드렸고 아래과 같은 점을 알게되었습니다.
RxSwift는 외부 프레임워크이고 도메인에서 사용시 클린 아키텍처에는 위배되지만 개발 효율이 올라간다는 점에서 충분이 도입가능하다고 생각하게되었습니다.
아키텍처보다 개발효율성이 우선될 수도 있습니다. 아키텍처에 너무 목메기보단 적절한 방법을 선택하는 것이 중요하다고 하셨습니다.

@J0onYEong J0onYEong merged commit 727ed51 into develop Jun 28, 2024
1 check passed
@J0onYEong J0onYEong deleted the feature/network_base branch June 28, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant