Few words about Swift. Swift - Java annotation-based generator for Apache Thrift. It's priceless when you develop your APIs in Java and want to expose them to the other world using Apache Thrift.
Protocol
Lets recreate our previous example ( https://github.com/bsideup/spring-boot-thrift ) with it. Start with simple build.gradle file:Nothing special, Spring Boot with few Facebook Swift libraries.
Next we need to add Swift protocol classes:
Exception is simple Swift struct which extend Exception (See Ma no TException)
Enums are handled with Swift, so we don't need to annotate them (but we can)
Next - application main class for Spring Boot:
Test
Now we're ready to write some tests:As you can see, only difference here (compared to Thrift version) is setUp method.
Diff with Thrift version
Implementation
We still have no Swift service implementation. Implementation of handler looks almost the same as previous:Diff with Thrift version
Now if you will run tests you should see all tests green.
Thrift integration
But hey, how about other non-Java consumers of service? Don't worry, Swift comes with a tool for generating *.thrift files from annotated Java classes: https://github.com/facebook/swift/tree/master/swift2thrift-generator-cliExample output for our service will be:
Conclusion
Full source files for this example can be found at GitHub: https://github.com/bsideup/spring-boot-swiftNext time I will show you how to write Async Thrift services using Swift with minimal changes. Stay tuned!