Skip to content

🎟️ Ticketing Service Example

This example shows how to build a simple ticketing service using Nylon, supporting create, view, delete, update, and book operations β€” with plugins written in Go and Rust.


  • Nylon >= 1.0.0-beta.0
  • Go
  • Rust

Terminal window
nylon plugin init ticketing-service
cd ticketing-service
Terminal window
nylon plugin add ticketing-svc --lang go --type ffi
nylon plugin add mid-authz --lang rust --type ffi

ticketing-service/
β”œβ”€β”€ c/
β”‚ └── nylon.h # C header for FFI plugins
β”œβ”€β”€ build/
β”‚ β”œβ”€β”€ ticketing-svc.so # Compiled Go plugin
β”‚ └── mid-authz.so # Compiled Rust plugin
β”œβ”€β”€ config/
β”‚ β”œβ”€β”€ conf.d/
β”‚ β”‚ β”œβ”€β”€ __plugins.yaml # Auto-generated by Nylon CLI
β”‚ β”‚ └── routes.yaml # Route configuration
β”‚ └── config.yaml # Global Nylon config
β”œβ”€β”€ ffi/
β”‚ β”œβ”€β”€ ticketing-svc/
β”‚ β”‚ β”œβ”€β”€ main.go # Main Go plugin code
β”‚ β”‚ β”œβ”€β”€ go.mod
β”‚ β”‚ └── go.sum
β”‚ └── mid-authz/
β”‚ β”œβ”€β”€ Cargo.toml
β”‚ └── src/
β”‚ └── lib.rs # Main Rust plugin code
β”œβ”€β”€ plugins.yaml # Declare plugin metadata
β”œβ”€β”€ .gitignore
└── README.md

Terminal window
nylon plugin dev
# Watches for changes and automatically rebuilds plugins

ticketing-svc/main.go
//go:build cgo
package main
/*
#include "../../c/nylon.h"
*/
import "C"
import (
"unsafe"
"github.com/AssetsArt/nylon/sdk/go/sdk"
)
func main() {}
func SendResponse(sdk_dispatcher *sdk.Dispatcher) C.FfiOutput {
output := sdk_dispatcher.ToBytes()
return C.FfiOutput{
ptr: (*C.uchar)(C.CBytes(output)),
len: C.ulong(len(output)),
}
}
func InputToDispatcher(ptr *C.uchar, input_len C.int) *sdk.Dispatcher {
input := C.GoBytes(unsafe.Pointer(ptr), C.int(input_len))
dispatcher := sdk.WrapDispatcher(input)
return dispatcher
}
/*
This function is used to free the memory allocated by the plugin.
It is called by the Nylon runtime.
*/
//export plugin_free
func plugin_free(ptr *C.uchar) {
C.free(unsafe.Pointer(ptr))
}
//export create_ticket
func create_ticket(ptr *C.uchar, input_len C.int) C.FfiOutput {
dispatcher := InputToDispatcher(ptr, input_len)
http_ctx := dispatcher.SwitchDataToHttpContext()
// TODO: Implement the create ticket logic
// set http end and data
dispatcher.SetHttpEnd(true) // set http end to true
dispatcher.SetData(http_ctx.ToBytes()) // set data to http context
return SendResponse(dispatcher)
}

  • Hot-reload: Save your plugin code and nylon plugin dev will auto-rebuild and reload plugins.
  • Route mapping: Map HTTP routes to plugin entrypoints via routes.yaml.
  • Multi-language support: You can combine Go, Rust, Zig plugins in a single project.
  • Explore more: See Nylon plugin docs for all SDK options.

Happy Coding!