Created
August 16, 2019 13:06
-
-
Save manishkkatoch/7a86ade0e85617f4f4f162d1ee644faa to your computer and use it in GitHub Desktop.
HATEOAS Root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Root: Decodable {} | |
extension Resource where T:Root { | |
func hasLibrary() -> Bool { | |
return self.hasCapability(for: "library") | |
} | |
func getLibraryLink() -> Link? { | |
return self.getRelation(forRel: "library") | |
} | |
func getCartLink() -> Link? { | |
return self.getRelation(forRel: "cart") | |
} | |
func library(onAvailable: LinkAvailableHandler? = nil, onUnavailable: LinkUnAvailableHandler? = nil){ | |
capabilityMap(forRel: "library", onAvailable, onUnavailable) | |
} | |
func cart(onAvailable: LinkAvailableHandler? = nil, onUnavailable: LinkUnAvailableHandler? = nil){ | |
capabilityMap(forRel: "cart", onAvailable, onUnavailable) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment