A high-performance Go API service that provides both HTTP REST and gRPC interfaces for steel beam data management and structural engineering applications.
This service operates as part of a microservice architecture:
Frontend Clients β HTTP REST API (Port 8080) β Go API Service
β
Python Calc Engine β gRPC API (Port 9090) βββ
- Dual Protocol Support: HTTP REST for frontend clients, gRPC for backend services
- Steel Beam Database: Comprehensive UK steel beam section data
- CORS Enabled: Ready for web frontend integration
- Type-Safe gRPC: Protobuf-based service definitions
- Health Monitoring: Built-in health check endpoints
- Production Ready: Optimized for Railway deployment
| Method | Endpoint | Description | Response |
|---|---|---|---|
GET |
/ |
Service information | Service details |
GET |
/health |
Health check | Service status |
GET |
/beams |
Get all steel beams | Array of beam objects |
GET |
/beams/{section} |
Get specific beam | Single beam object |
POST |
/beams |
Create new beam | Created beam object |
PUT |
/beams/{section} |
Update existing beam | Updated beam object |
DELETE |
/beams/{section} |
Delete beam | Success/error message |
| Service | Method | Description |
|---|---|---|
SteelBeamService |
GetBeams() |
Retrieve all beams |
SteelBeamService |
GetBeam(section) |
Get specific beam |
SteelBeamService |
CreateBeam(data) |
Create new beam |
- Go 1.21 or later
- Protocol Buffers compiler (
protoc) - Go protobuf plugins
-
Clone the repository
git clone <your-repo-url> cd formandfunction-api
-
Install dependencies
go mod tidy
-
Generate protobuf files
chmod +x build_proto.sh ./build_proto.sh
-
Run the service
export PORT=8080 export GRPC_PORT=9090 go run .
# Test HTTP endpoints
curl http://localhost:8080/health
curl http://localhost:8080/beams
# Test gRPC (requires grpcurl)
grpcurl -plaintext localhost:9090 list
grpcurl -plaintext localhost:9090 steelbeam.SteelBeamService/GetBeamsPORT=8080
GRPC_PORT=9090
GO_ENV=production
Set up your custom domain in Railway to point to: api.itsformfunction.com
Railway automatically:
- Runs
build_proto.shto generate protobuf files - Executes
go build -o main . - Starts the service with
./main
Ensure Railway exposes both ports:
- 8080: HTTP REST API (for frontend clients)
- 9090: gRPC API (for backend services)
For production, update CORS settings in main.go:
app.Use(cors.New(cors.Config{
AllowOrigins: []string{
"https://yourfrontend.com",
"https://app.yourfrontend.com",
},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Content-Type", "Authorization"},
AllowCredentials: true,
}))| Variable | Description | Default |
|---|---|---|
PORT |
HTTP server port | 8080 |
GRPC_PORT |
gRPC server port | 9090 |
GO_ENV |
Environment mode | development |
- HTTP:
GET /health - gRPC: Service reflection enabled
All requests and gRPC calls are logged with:
- Request/response times
- Status codes
- Error details
- Client information
- Enable HTTPS/TLS for HTTP endpoints
- Enable TLS for gRPC communication
- Restrict CORS origins to your frontend domains
- Implement API rate limiting
- Add request validation middleware
- Set up proper error handling (don't expose internal errors)
Use the verification script:
python ../verify_production_deployment.py --api-onlyOr test manually:
# Health check
curl https://api.itsformfunction.com/health
# Get all beams
curl https://api.itsformfunction.com/beams
# Test specific beam
curl https://api.itsformfunction.com/beams/UB406x178x74The service includes comprehensive UK steel beam data with properties:
- Section designation (e.g., "UB406x178x74")
- Mass per metre (kg/m)
- Dimensional properties (depth, width, thickness)
- Section properties (moments of inertia, elastic moduli)
- Local buckling ratios
- Torsional properties
# Format code
go fmt ./...
# Run tests
go test ./...
# Build binary
go build -o main .
# Generate protobuf files
./build_proto.sh
# Run with specific ports
PORT=8080 GRPC_PORT=9090 go run .const API_BASE_URL = 'https://api.itsformfunction.com'
export const beamApi = {
getBeams: () =>
fetch(`${API_BASE_URL}/beams`).then(res => res.json()),
getBeam: (section: string) =>
fetch(`${API_BASE_URL}/beams/${section}`).then(res => res.json()),
createBeam: (beam: SteelBeam) =>
fetch(`${API_BASE_URL}/beams`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(beam)
}).then(res => res.json()),
}import { useQuery } from '@tanstack/react-query'
export function useBeams() {
return useQuery({
queryKey: ['beams'],
queryFn: beamApi.getBeams,
staleTime: 5 * 60 * 1000, // 5 minutes
})
}- HTTP REST: Optimized for frontend clients with JSON responses
- gRPC: High-performance binary protocol for service communication
- Memory: Efficient in-memory beam data storage
- Concurrency: Go's goroutines handle multiple concurrent requests
- Port conflicts: Ensure ports 8080 and 9090 are available
- Protobuf errors: Run
./build_proto.shto regenerate files - CORS issues: Check frontend domain is in allowed origins
- gRPC connection: Verify gRPC port is exposed in Railway
Set environment variable for verbose logging:
export LOG_LEVEL=debug
go run .[Your License Here]
π Production URL: https://api.itsformfunction.com
For the complete microservice architecture documentation, see ../MICROSERVICE_DEPLOYMENT_GUIDE.md