Skip to content

Commit e40c865

Browse files
authored
Changed the APIRouter name to URLRouter which is a universal meaning (#33)
1 parent 648342d commit e40c865

File tree

16 files changed

+151
-96
lines changed

16 files changed

+151
-96
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
test:
1313
runs-on: macOS-latest
1414
env:
15-
PROJECT: APIRouter.xcodeproj
16-
SCHEME: APIRouter-Package
17-
CODECOV_PACKAGE_NAME: APIRouter
15+
PROJECT: URLRouter.xcodeproj
16+
SCHEME: URLRouter-Package
17+
CODECOV_PACKAGE_NAME: URLRouter
1818
strategy:
1919
matrix:
2020
env:
Binary file not shown.

Package.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
import PackageDescription
44

55
let package = Package(
6-
name: "APIRouter",
7-
platforms: [
8-
.iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)
9-
],
10-
products: [
11-
.library(
12-
name: "APIRouter",
13-
targets: ["APIRouter"]),
14-
],
15-
dependencies: [],
16-
targets: [
17-
.target(
18-
name: "APIRouter",
19-
dependencies: []),
20-
.testTarget(
21-
name: "APIRouterTests",
22-
dependencies: ["APIRouter"]),
23-
]
6+
name: "URLRouter",
7+
platforms: [
8+
.iOS(.v13), .macOS(.v10_15), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)
9+
],
10+
products: [
11+
.library(
12+
name: "URLRouter",
13+
targets: ["URLRouter"]),
14+
],
15+
dependencies: [],
16+
targets: [
17+
.target(
18+
name: "URLRouter",
19+
dependencies: []),
20+
.testTarget(
21+
name: "URLRouterTests",
22+
dependencies: ["URLRouter"]),
23+
]
2424
)

README.md

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
![main](https://github.com/devyhan/apirouter/actions/workflows/ci.yml/badge.svg?branch=main)
2-
[![codecov](https://codecov.io/gh/devyhan/APIRouter/branch/main/graph/badge.svg?token=ZQNDOX2VDF)](https://codecov.io/gh/devyhan/APIRouter)
1+
![main](https://github.com/devyhan/urlrouter/actions/workflows/ci.yml/badge.svg?branch=main)
2+
[![codecov](https://codecov.io/gh/devyhan/URLRouter/branch/main/graph/badge.svg?token=ZQNDOX2VDF)](https://codecov.io/gh/devyhan/APIRouter)
33
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdevyhan%2FAPIRouter%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/devyhan/APIRouter)
44
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdevyhan%2FAPIRouter%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/devyhan/APIRouter)
55

66
<p align="center">
77
<img src="https://user-images.githubusercontent.com/45344633/208562346-19b44df3-c581-4f32-af8e-d85dbc99ec18.png" />
88
</p>
99

10-
## What's APIRouter 📟
11-
***APIRouter*** is provides an easy way to manage multiple RESTful API endpoints in Swift.
10+
## What's URLRouter 📟
11+
***URLRouter*** is provides an easy way to manage multiple URL endpoints in Swift.
1212
It provides a simple interface for managing multiple endpoints and allows developers to interact with them in a single, unified manner.
1313
It also provides a way for developers to create custom endpoints DSL(Domain-Specific Languages) and to manage their own settings for each endpoint.
1414
Additionally, it provides a way to track the status of each endpoint and to easily detect any changes or updates that have been made.
1515

1616
Similar to Swift Evolution's [Regex builder DSL](https://github.com/apple/swift-evolution/blob/main/proposals/0351-regex-builder.md), URL string literal and a more powerful pattern result builder to help make Swift URL string processing fast and easy and without mistakes. Ultimately, with ***APIRouter***, changes are easy to detect and useful for maintenance.
1717

18-
🤔 *Ask questions you’re wondering about [here](https://github.com/devyhan/APIRouter/discussions/new?category=q-a).*<br/>
18+
🤔 *Ask questions you’re wondering about [here](https://github.com/devyhan/URLRouter/discussions/new?category=q-a).*<br/>
1919
💡 *Share ideas [here](https://github.com/devyhan/APIRouter/discussions/new).*
2020

2121
## Installation 📦
@@ -27,18 +27,18 @@ Similar to Swift Evolution's [Regex builder DSL](https://github.com/apple/swift-
2727
let package = Package(
2828
name: "SomeApp",
2929
dependencies: [
30-
.Package(url: "https://github.com/devyhan/APIRouter", majorVersion: "<LATEST_RELEASES_VERSION>"),
30+
.Package(url: "https://github.com/devyhan/URLRouter", majorVersion: "<LATEST_RELEASES_VERSION>"),
3131
]
3232
)
3333
```
3434

35-
## Configure APIRouter 📝
36-
### Implement APIs Namespace
37-
- To implement APIs namespace we create a new type that will house the domain and behavior of the APIs by conforming to `RouterProtocol`.
35+
## Configure URLRouter 📝
36+
### Implement URLs Namespace
37+
- To implement URLs namespace we create a new type that will house the domain and behavior of the URLs by conforming to `RouterProtocol`.
3838
```swift
39-
import APIRouter
39+
import URLRouter
4040

41-
public enum APIs: RouterProtocol {
41+
public enum URLs: RouterProtocol {
4242
...
4343
}
4444
```
@@ -231,18 +231,19 @@ Request {
231231
}
232232
```
233233
---
234-
### How to configure and use ***APIRouter*** in a real project?
235-
- Just create APIRouter.swift in your project! Happy hacking! 😁
234+
### How to configure and use ***URLRouter*** in a real world project?
235+
- Just create URLRouter.swift in your project! Happy hacking! 😁
236236
```swift
237-
import APIRouter
237+
import URLRouter
238238

239-
enum APIs: RouterProtocol {
239+
enum URLs: RouterProtocol {
240240
// DOC: https://docs.github.com/ko/rest/repos/repos?apiVersion=2022-11-28#list-organization-repositories
241241
case listOrganizationRepositories(organizationName: String)
242242
// DOC: https://docs.github.com/ko/rest/repos/repos?apiVersion=2022-11-28#create-an-organization-repository
243243
case createAnOrganizationRepository(organizationName: String, repositoryInfo: RepositoryInfo)
244244
// DOC: https://docs.github.com/ko/rest/search?apiVersion=2022-11-28#search-repositories
245245
case searchRepositories(query: String)
246+
case deeplink(path: String = "home")
246247

247248
struct RepositoryInfo {
248249
let name: String
@@ -304,25 +305,53 @@ enum APIs: RouterProtocol {
304305
Query("q", value: query)
305306
}
306307
}
308+
case let .deeplink(path):
309+
URL {
310+
Scheme.custom("example-deeplink")
311+
Host("detail")
312+
Path(path)
313+
Query {
314+
Field("postId", forKey: "1")
315+
Field("createdAt", forKey: "2021-04-27T04:39:54.261Z")
316+
}
317+
}
307318
}
308319
}
309320
}
310321
}
311322

312323
// http://api.github.com/orgs/organization/repos
313-
let listOrganizationRepositoriesUrl = APIs.listOrganizationRepositories(organizationName: "organization").router?.urlRequest?.url
324+
let listOrganizationRepositoriesUrl = URLs.listOrganizationRepositories(organizationName: "organization").router?.urlRequest?.url
314325

315-
// http://api.github.com/search/repositories?q=apirouter
316-
let searchRepositoriesUrl = APIs.searchRepositories(query: "apirouter").router?.urlRequest?.url
326+
// http://api.github.com/search/repositories?q=urlrouter
327+
let searchRepositoriesUrl = URLs.searchRepositories(query: "urlrouter").router?.urlRequest?.url
317328

318-
let repositoryInfo: APIs.RepositoryInfo = .init(name: "Hello-World", description: "This is your first repository", homePage: "https://github.com", private: false, hasIssues: true, hasProjects: true, hasWiki: false)
319-
let request = APIs.createAnOrganizationRepository(organizationName: "SomeOrganization", repositoryInfo: repositoryInfo).router?.urlRequest
329+
// example-deeplink://detail/comments?1=postId&2021-04-27T04:39:54.261Z=createdA
330+
let deeplink = URLs.deeplink(path: "detail").router.url
331+
```
332+
- Using ***URLRouter*** to provide `URLRequest`.
333+
```swift
334+
let repositoryInfo: URLs.RepositoryInfo = .init(name: "Hello-World", description: "This is your first repository", homePage: "https://github.com", private: false, hasIssues: true, hasProjects: true, hasWiki: false)
335+
let request = URLs.createAnOrganizationRepository(organizationName: "SomeOrganization", repositoryInfo: repositoryInfo).router?.urlRequest
320336

321337
URLSession.shared.dataTask(with: request) { data, response, error in
322338
...
323339
```
340+
- Using ***URLRouter*** to provide deeplink `URL` and check to match this `URL`.
341+
```swift
342+
class AppDelegate: UIResponder, UIApplicationDelegate {
343+
...
344+
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]) -> Bool {
345+
let detailDeeplink = URLs.deeplink(path: "detail").router.url
346+
if detailDeeplink == url {
347+
...
348+
}
349+
...
350+
```
324351
## License
325352

326-
***APIRouter*** is under MIT license. See the [LICENSE](LICENSE) file for more info.
353+
***URLRouter*** is under MIT license. See the [LICENSE](LICENSE) file for more info.
327354

355+
---
356+
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/devyhan/urlrouter?style=social)
328357
[![Twitter Follow @devyhan93](https://img.shields.io/twitter/follow/devyhan93?style=social)](https://twitter.com/devyhan93)
Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum HttpMethod: String {
1414
}
1515

1616
public protocol RequestProtocol {
17-
func build(_ apiRequest: inout Request)
17+
func build(_ request: inout Request)
1818
}
1919

2020
@resultBuilder
@@ -24,16 +24,16 @@ public struct RequestBuilder {
2424
}
2525
}
2626

27-
private struct CombinedRequest: RequestProtocol {
27+
struct CombinedRequest: RequestProtocol {
2828
private let children: Array<RequestProtocol>
2929

3030
init(_ children: Array<RequestProtocol>) {
3131
self.children = children
3232
}
3333

34-
func build(_ apiRequest: inout Request) {
34+
func build(_ request: inout Request) {
3535
children.forEach {
36-
$0.build(&apiRequest)
36+
$0.build(&request)
3737
}
3838
}
3939
}
@@ -82,8 +82,8 @@ public struct Method: RequestProtocol {
8282
self.method = method
8383
}
8484

85-
public func build(_ apiRequest: inout Request) {
86-
apiRequest.urlRequest?.httpMethod = method.rawValue
85+
public func build(_ request: inout Request) {
86+
request.urlRequest?.httpMethod = method.rawValue
8787
}
8888
}
8989

@@ -94,9 +94,9 @@ public struct Header: RequestProtocol {
9494
self.headers = headers
9595
}
9696

97-
public func build(_ apiRequest: inout Request) {
97+
public func build(_ request: inout Request) {
9898
for header in headers {
99-
apiRequest.urlRequest?.addValue(header.value, forHTTPHeaderField: header.key)
99+
request.urlRequest?.addValue(header.value, forHTTPHeaderField: header.key)
100100
}
101101
}
102102
}
@@ -108,30 +108,41 @@ public struct Body: RequestProtocol {
108108
self.body = body
109109
}
110110

111-
public func build(_ apiRequest: inout Request) {
111+
public func build(_ request: inout Request) {
112112
do {
113113
let jsonData = try JSONSerialization.data(withJSONObject: self.body, options: .fragmentsAllowed)
114-
apiRequest.urlRequest?.httpBody = jsonData
114+
request.urlRequest?.httpBody = jsonData
115115
} catch {
116116
print("Error \(error)")
117117
}
118118
}
119119
}
120120

121-
public struct URL: RequestProtocol {
121+
public struct URL: RequestProtocol, URLRouterProtocol {
122122
var components: URLComponents?
123123
var queryItems: Array<URLQueryItem> = []
124124

125125
public init(_ url: String) {
126126
self.components = URLComponents(string: url)
127127
}
128128

129-
public func build(_ apiRequest: inout Request) {
130-
apiRequest.urlComponents = self.components
131-
apiRequest.urlRequest?.url = self.components?.url
129+
public func build(_ request: inout Request) {
130+
request.urlComponents = self.components
131+
request.urlRequest?.url = self.components?.url
132132
if !queryItems.isEmpty {
133-
apiRequest.urlComponents?.queryItems = self.queryItems
134-
apiRequest.urlRequest?.url = apiRequest.urlComponents?.url
133+
request.urlComponents?.queryItems = self.queryItems
134+
request.urlRequest?.url = request.urlComponents?.url
135+
}
136+
}
137+
138+
public func build(_ router: inout URLRouter) {
139+
router.urlComponents = self.components
140+
router.urlRequest?.url = self.components?.url
141+
router.url = self.components?.url
142+
if !queryItems.isEmpty {
143+
router.urlComponents?.queryItems = self.queryItems
144+
router.urlRequest?.url = router.urlComponents?.url
145+
router.url = router.urlComponents?.url
135146
}
136147
}
137148
}

0 commit comments

Comments
 (0)