github.com/anycable/anycable-go@v1.5.1/docs/library.md (about) 1 # Using anycable-go as a library 2 3 You can use AnyCable-Go as a library to build custom real-time applications. 4 5 > Read ["AnyCable off Rails: connecting Twilio streams with Hanami"](https://evilmartians.com/chronicles/anycable-goes-off-rails-connecting-twilio-streams-with-hanami) to learn how we've integrated Twilio Streams with a Hanami application via AnyCable-Go. 6 7 Why building a WebSocket application with AnyCable-Go (and not other Go libraries)? 8 9 - Connect your application to Ruby/Rails apps with ease by using AnyCable RPC protocol. 10 - Many features out-of-the-box including different pub/sub adapters (including [embedded NATS](./embedded_nats.md)), built-in instrumentation. 11 - Bulletproof code, which has been used production for years. 12 13 To get started with an application development with AnyCable-Go, you can use our template repository: [anycable-go-scaffold](https://github.com/anycable/anycable-go-scaffold). 14 15 ## Embedding 16 17 You can also embed AnyCable into your existing web application in case you want to serve AnyCable WebSocket/SSE connections via the same HTTP server as other requests (e.g., if you build a smart reverse-proxy). 18 19 Here is a minimal example Go code (you can find the full and up-to-date version [here](https://github.com/anycable/anycable-go/blob/master/cmd/embedded-cable/main.go)): 20 21 ```go 22 package main 23 24 import ( 25 "net/http" 26 27 "github.com/anycable/anycable-go/cli" 28 ) 29 30 func main() { 31 opts := []cli.Option{ 32 cli.WithName("AnyCable"), 33 cli.WithDefaultRPCController(), 34 cli.WithDefaultBroker(), 35 cli.WithDefaultSubscriber(), 36 cli.WithDefaultBroadcaster(), 37 } 38 39 c := cli.NewConfig() 40 runner, _ := cli.NewRunner(c, opts) 41 anycable, _ := runner.Embed() 42 43 wsHandler, _ := anycable.WebSocketHandler() 44 http.Handle("/cable", wsHandler) 45 46 http.ListenAndServe(":8080", nil) 47 } 48 ```