This repository includes an example Apodini web service that can be used to control LIFX smart lights using NIO LIFX.
An Apodini web service is build using Swift and uses Swift Packages. You can learn more about the Swift Package Manager at swift.org.
If you use macOS, you can use Xcode to open the Package.swift
file at the root of the repository using Xcode. You can learn more on how to use Swift Packages with Xcode on developer.apple.com.
If you are not using macOS or don't want to use Xcode, you can use Visual Studio Code using the Remote Containers plugin. You must install the latest version of Visual Studio Code, the latest version of the Remote Containers plugin and Docker.
- Open the folder using Visual Studio Code
- If you have installed the Remote Containers plugin Visual Studio Code automatically asks you to reopen the folder to develop in a container at the bottom right of the Visual Studio Code window.
- Press "Reopen in Container" and wait until the docker container is build
- You can now build the code using the build keyboard shortcut and run and test the code within the docker container using the Run and Debug area.
The web service exposes a RESTful web API and an OpenAPI description.
It includes Handler
s to
- Send out discovery messages (
DiscoverDevices
) - Get all devices that are currently discovered (
GetAllDevices
) - Change the power level of a device (
ChangeDeviceState
).
In addition the Apodini web service includes a Job
that is triggered every minute to discover new devices on the network (DiscoveryJob
).
- You can access the
DiscoverDevices
Handler
athttp://localhost:8080/v1/discover
using aPOST
request. - You can access the
GetAllDevices
Handler
athttp://localhost:8080/v1/devices
using aGET
request. - You can access the
ChangeDeviceState
Handler
athttp://localhost:8080/v1/devices/DEVICE_NAME
using aPUT
request. TheDEVICE_NAME
in the path indicates the device's name you try to address. ThePUT
request must include the new state in the new state in the HTTP Body, e.g.:
"on"
You can access the OpenAPI document at http://localhost:8080/openapi
.
The Swagger UI is also automatically generated and accessible at http://localhost:8080/openapi-ui
.
The repository contains GitHub Actions to automatically build and test the example web service on a wide variety of platforms and configurations.