Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Jul 24, 2022. It is now read-only.
/AmacaPodPublic archive

A restful network interface with Codable

License

NotificationsYou must be signed in to change notification settings

3zcurdia/AmacaPod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCI StatusVersionLicensePlatformMaintainability

Installation

Amaca is available throughCocoaPods. To installit, simply add the following line to your Podfile:

pod'Amaca'

Setup

Even when Amaca is based in convention over configuration principle, there are few things to setup.

AmacaConfigurable Protocol

You must implement a structure or a class conforming theAmacaConfigurable protocol whereit will be defined the base url and the session for your connections, among with the authentication structureif needed.

publicprotocolServicesConfig{varsession:URLSession{get}varbaseURL:URL{get}}

Example

structServicesConfig:AmacaConfigurable{letsession:URLSession=URLSession.sharedletbaseUrl:URL=URL(string:"https://example.com/api")!}

Usage

To initialize a service you must create an instance with the Codable you desireto parse a config and the path where all the RESTFUL routes reside.

MethodURI PatternAction
GET/usersindex
POST/userscreate
GET/users/:idshow
PUT/users/:idupdate
DELETE/users/:iddestroy

Then for each method you can call the correspondent action

Example Unauthenticated

letconfig=ServicesConfig()letservice=CodableService<User>(config: config, path:"/users", auth:nil)  service.index{ responsein    // your code goes hereswitch response.status{case.success:print(response.data!.count)default:print(response.status)print(response)}}

Authentication

Amaca provides authentication structs for query and header:

  • QueryAuthentication
  • HeaderAuthentication

Example Authenticated

letconfig=ServicesConfig()letauth=QueryAuthentication(method:.basicHeader, token:"secret-token-1234")letservice=CodableService<User>(config: config, path:"users", auth: auth)  service.index{ responsein    // your code goes hereswitch response.status{case.success:print(response.data!.count)default:print(response.status)print(response)}}

Note: CodableService internally implementsdataTask other methods fromURLSession could be supported in the future.

Contribute to the project

To contribute, just follow the next steps:

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • It is desired to add some tests for it.
  • Make a Pull Request

License

Amaca is available under the MIT license. See the LICENSE file for more info.

About

A restful network interface with Codable

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp