- Notifications
You must be signed in to change notification settings - Fork1
Provides an easy way to manage namespace of multiple URL endpoints in Swift.
License
devyhan/URLRouter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
URLRouter is provides an easy way to manage multiple URL endpoints in Swift.It provides a simple interface for managing multiple endpoints and allows developers to interact with them in a single, unified manner.It also provides a way for developers to create custom endpoints DSL(Domain-Specific Languages) and to manage their own settings for each endpoint.Additionally, it provides a way to track the status of each endpoint and to easily detect any changes or updates that have been made.
Similar to Swift Evolution'sRegex builder DSL, URL string literal and a more powerful pattern result builder to help make Swift URL string processing fast and easy and without mistakes. Ultimately, withURLRouter, changes are easy to detect and useful for maintenance.
🤔Ask questions you’re wondering abouthere.
💡Share ideashere.
import PackageDescriptionletpackage=Package( name:"SomeApp", dependencies:[.Package(url:"https://github.com/devyhan/URLRouter", majorVersion:"<LATEST_RELEASES_VERSION>"),])
- To implement URLs namespace we create a new type that will house the domain and behavior of the URLs by conforming to
URLRoutable.
import URLRouterpublicenumURLs:URLRoutable{...}
- Using
HeaderBuildertohttpHeaderdeclaration.
Request{...Header{Field("HEADERVALUE", forKey:"HEADERKEY")Field("HEADERVALUE1", forKey:"HEADERKEY1")Field("HEADERVALUE2", forKey:"HEADERKEY2")...}...}
- Using
DictionarytohttpHeaderdeclaration.
Request{...Header(["HEADERKEY":"HEADERVALUE","HEADERKEY1":"HEADERVALUE1","HEADERKEY2":"HEADERVALUE2",...])...}
- Using
HeaderBuildertohttpHeaderdeclaration.
Request{...Body{Field("VALUE", forKey:"KEY")Field("VALUE1", forKey:"KEY1")Field("VALUE2", forKey:"KEY2")...}...}
- Using
Dictionary<String, Any>tohttpHeaderdeclaration.
Request{...Body(["KEY":"VALUE","KEY1":"VALUE1","KEY2":"VALUE2",...])...}
- Using
Method(_ method:)tohttpMethoddeclaration.
Request{...Method(.get)...}
- Using
static let method:tohttpMethoddeclaration.
Request{...Method.get...}
- Using
URL(_ url:)toURLdeclaration.
Request{...URL("https://www.baseurl.com/comments?postId=1")...}
- Using
URLBuildertoURLdeclaration andURLComponentsdeclaration.
Request{...URL{Scheme(.https)Host("www.baseurl.com")Path("comments")Query("postId", value:"1")}...}// https://www.baseurl.com/comments?postId=1
- Using
BaseURL(_ url:)forURLoverride.
Request{BaseURL("https://www.baseurl.com")URL{Path("comments")Query("postId", value:"1")}}// https://www.baseurl.com/comments?postId=1Router{BaseURL("https://www.baseurl.com")Request{URL{Scheme(.https)Host("www.overrideurl.com")Path("comments")Query("postId", value:"1")}}}// https://www.overrideurl.com/comments?postId=1
- Using
Scheme(_ scheme:)toSchemedeclaration.
Request{...URL{Scheme(.https)...}...}
- Using
static let scheme:toSchemedeclaration.
Request{...URL{Scheme.https...}...}
- Using
Dictionary<String, String?>toQuerydeclaration.
Request{...URL{Query(["first":"firstQuery","second":"secondQuery",...])}...}
- Using
Query(_, value:)toQuerydeclaration.
Request{...URL{Query("test", value:"query")Query("test", value:"query")...}...}
- Using
Field(_, forKey:)toQuerydeclaration.
Request{...URL{Query{Field("firstQuery", forKey:"first")Field("secondQuery", forKey:"second")...}...}...}
- Just create URLRouter.swift in your project! Happy hacking! 😁
import URLRouterenumURLs:URLRoutable{ // DOC: https://docs.github.com/ko/rest/repos/repos?apiVersion=2022-11-28#list-organization-repositoriescase listOrganizationRepositories(organizationName:String) // DOC: https://docs.github.com/ko/rest/repos/repos?apiVersion=2022-11-28#create-an-organization-repositorycase createAnOrganizationRepository(organizationName:String, repositoryInfo:RepositoryInfo) // DOC: https://docs.github.com/ko/rest/search?apiVersion=2022-11-28#search-repositoriescase searchRepositories(query:String)case deeplink(path:String="home")structRepositoryInfo{letname:Stringletdescription:StringlethomePage:Stringlet`private`:BoollethasIssues:BoollethasProjects:BoollethasWiki:Bool}varrouter:URLRouter{URLRouter{BaseURL("http://api.github.com")switchself{caselet.listOrganizationRepositories(organizationName):Request{Method.postHeader{Field("application/vnd.github+json", forKey:"Accept")Field("Bearer <YOUR-TOKEN>", forKey:"Authorization")Field("2022-11-28", forKey:"X-GitHub-Api-Version")}URL{Path("orgs/\(organizationName)/repos")}}caselet.createAnOrganizationRepository(organizationName, repositoryInfo):Request{Method.postHeader{Field("application/vnd.github+json", forKey:"Accept")Field("Bearer <YOUR-TOKEN>", forKey:"Authorization")Field("2022-11-28", forKey:"X-GitHub-Api-Version")}URL{Path("orgs/\(organizationName)/repos")}Body{Field(repositoryInfo.name, forKey:"name")Field(repositoryInfo.description, forKey:"description")Field(repositoryInfo.homePage, forKey:"homepage")Field(repositoryInfo.private, forKey:"private")Field(repositoryInfo.hasIssues, forKey:"has_issues")Field(repositoryInfo.hasProjects, forKey:"has_projects")Field(repositoryInfo.hasWiki, forKey:"has_wiki")}}caselet.searchRepositories(query):Request{Method.getHeader{Field("application/vnd.github+json", forKey:"Accept")Field("Bearer <YOUR-TOKEN>", forKey:"Authorization")Field("2022-11-28", forKey:"X-GitHub-Api-Version")}URL{Path("search/repositories")Query("q", value: query)}}caselet.deeplink(path):URL{Scheme.custom("example-deeplink")Host("detail")Path(path)Query{Field("postId", forKey:"1")Field("createdAt", forKey:"2021-04-27T04:39:54.261Z")}}}}}}// http://api.github.com/orgs/organization/reposletlistOrganizationRepositoriesUrl=URLs.listOrganizationRepositories(organizationName:"organization").router?.urlRequest?.url// http://api.github.com/search/repositories?q=urlrouterletsearchRepositoriesUrl=URLs.searchRepositories(query:"urlrouter").router?.urlRequest?.url// example-deeplink://detail/comments?1=postId&2021-04-27T04:39:54.261Z=createdAletdeeplink=URLs.deeplink(path:"detail").router.url
- UsingURLRouter to provide
URLRequest.
letrepositoryInfo:URLs.RepositoryInfo=.init(name:"Hello-World", description:"This is your first repository", homePage:"https://github.com", private:false, hasIssues:true, hasProjects:true, hasWiki:false)letrequest=URLs.createAnOrganizationRepository(organizationName:"SomeOrganization", repositoryInfo: repositoryInfo).router?.urlRequestURLSession.shared.dataTask(with: request){ data, response, error in...
- UsingURLRouter to provide deeplink
URLand check to match thisURL.
class AppDelegate:UIResponder,UIApplicationDelegate{...func application(_ app:UIApplication, open url:URL, options:[UIApplication.OpenURLOptionsKey:Any])->Bool{letdetailDeeplink=URLs.deeplink(path:"detail").router.urlif detailDeeplink== url{...}...
URLRouter is under MIT license. See theLICENSE file for more info.
About
Provides an easy way to manage namespace of multiple URL endpoints in Swift.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
