https://github.com/cpageler93/consulswift
Consul Client for Swift
https://github.com/cpageler93/consulswift
client consul http swift
Last synced: 3 months ago
JSON representation
Consul Client for Swift
- Host: GitHub
- URL: https://github.com/cpageler93/consulswift
- Owner: cpageler93
- License: mit
- Created: 2017-05-16T15:31:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-11T10:19:29.000Z (almost 8 years ago)
- Last Synced: 2025-09-18T06:48:27.530Z (5 months ago)
- Topics: client, consul, http, swift
- Language: Swift
- Size: 184 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 30
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# ConsulSwift
[](https://www.codacy.com/app/cpageler93/ConsulSwift?utm_source=github.com&utm_medium=referral&utm_content=cpageler93/ConsulSwift&utm_campaign=badger)
[](https://twitter.com/cpageler93)
[](https://github.com/cpageler93/ConsulSwift/blob/master/LICENSE)
[](https://www.consul.io)
[Consul](https://www.consul.io) Client for Swift
ConsulSwift connects to `http://localhost:8500` by default.
You can change the default behaviour by calling an other initializer.
```swift
let consul = Consul(url: otherBaseURL)
```
## Completeness of Content
I'm sure I haven't implemented all API Endpoints Consul provides. Feel free to create a pull request or create an issue.
## Examples
### Synchronous Example
```swift
// get consul instance
let consul = Consul()
// get agent members
let members = consul.agentMembers()
// check members result
switch members {
case .success(let members):
// do whatever you like with members which is kind of [ConsulAgentMember]
case .failure(let error):
// handle error
}
```
### Asynchronous Example
```swift
// get consul instance
let consul = Consul()
// get agent members
consul.agentMembers { members in
// check members result
switch members {
case .success(let members):
// do whatever you like with members which is kind of [ConsulAgentMember]
case .failure(let error):
// handle error
}
}
```
## Features
| Group | Endpoint | Route | Implemented |
|--------------------|---------------------------------|------------------------------------------|--------------|
| Agent - Base | List Members | GET /v1/agent/members | ✅ |
| | Read Configuration | GET /v1/agent/self | ✅ |
| | Reload Agent | PUT /v1/agent/reload | ✅ |
| | Enable Maintenance Mode | PUT /v1/agent/maintenance | ✅ |
| | Join Agent | GET /v1/agent/join/:id | ✅ |
| | Gracefull Leave + Shutdown | PUT /v1/agent/leave | ✅ |
| | Force Leave + Shutdown | PUT /v1/agent/force-leave | ✅ |
| | | | |
| Agent - Checks | List Checks | GET /v1/agent/checks | ✅ |
| | Register Check | PUT /v1/agent/check/register | ✅ |
| | Deregister Check | PUT /v1/agent/check/deregister/:id | ✅ |
| | TLL Check Pass | GET /v1/agent/check/pass/:id | ✅ |
| | TLL Check Warn | GET /v1/agent/check/warn/:id | ✅ |
| | TLL Check Fail | GET /v1/agent/check/fail/:id | ✅ |
| | TLL Check Update | GET /v1/agent/check/update/:id | ✅ |
| | | | |
| Agent - Services | List Services | GET /v1/agent/services | ✅ |
| | Register Service | PUT /v1/agent/service/register | ✅ |
| | Deregister Service | PUT /v1/agent/service/deregister/:id | ✅ |
| | Enable Maintenance Mode | PUT /v1/agent/service/maintenance/:id | ✅ |
| | | | |
| Catalog | List Datacenters | GET /v1/catalog/datacenters | ✅ |
| | List Nodes in a given DC | GET /v1/catalog/nodes | ✅ |
| | List Services in a given DC | GET /v1/catalog/services | ✅ |
| | List Nodes for Service | GET /v1/catalog/service/:id | ✅ |
| | List Services for Node | GET /v1/catalog/node/:id | ✅ |
| | | | |
| Coordinates | Read WAN Coordinates | GET /v1/coordinates/datacenters | ❌ |
| | Read LAN Coordinates | GET /v1/coordinates/nodes | ❌ |
| | | | |
| Events | Fire Event | PUT /v1/event/fire/:name | ✅ |
| | List Events | GET /v1/event/list | ✅ |
| | | | |
| Health | List Checks for Node | GET /v1/health/node/:id | ✅ |
| | List Checks for Service | GET /v1/health/checks/:id | ❌ |
| | List Nodes for Service | GET /v1/health/service/:id | ✅ |
| | List Checks in State | GET /v1/health/state/:state | ✅ |
| | | | |
| KV Store | Read Key | GET /v1/kv/:key | ✅ |
| | Create/Update Key | PUT /v1/kv/:key | ✅ |
| | Delete Key | DELETE /v2/kv/:key | ✅ |
| | | | |
## Test
To test ConsulSwift on your local machine you need to start consul first
```shell
# start consul
consul agent -dev -datacenter fra1
# test
swift test
```
## Need Help?
Please [submit an issue](https://github.com/cpageler93/ConsulSwift/issues) on GitHub or contact me via Mail or Twitter.
## License
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.