Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add REST API server mode #38

Merged
merged 1 commit into from
Nov 15, 2024
Merged

Conversation

appcypher
Copy link
Owner

@appcypher appcypher commented Nov 15, 2024

Overview

This PR adds a new server mode to monocore that exposes a REST API for managing services. The server provides endpoints for starting, stopping, checking status, and removing services.

Key changes

  • Added new serve subcommand to start monocore in server mode
  • Implemented REST API endpoints:
    • POST /up - Start services defined in config
    • POST /down - Stop running services
    • GET /status - Get status of all services
    • POST /remove - Remove service files
  • Added server-related modules:
    • handlers.rs - Request handlers for each endpoint
    • routes.rs - API route definitions
    • state.rs - Server state management
    • types.rs - Request/response type definitions
  • Updated README with API documentation and examples
  • Added default server port (3000) configuration

The REST API allows monocore to be integrated with other tools and services while maintaining the same functionality as the CLI. All operations available through the CLI can now be performed via HTTP requests.

Example usage

# Start services from config file
curl -X POST http://localhost:3000/up \
-H "Content-Type: application/json" \
-d @monocore.toml

# Start services in specific group
curl -X POST http://localhost:3000/up \
-H "Content-Type: application/json" \
-d '{"config": {...}, "group": "backend"}'

# Get status of all services
curl http://localhost:3000/status

# Stop all services in a group
curl -X POST http://localhost:3000/down \
-H "Content-Type: application/json" \
-d '{"group": "frontend"}'

# Stop all services
curl -X POST http://localhost:3000/down \
-H "Content-Type: application/json" \
-d '{}'

# Remove specific services
curl -X POST http://localhost:3000/remove \
-H "Content-Type: application/json" \
-d '{"services": ["web", "api"]}'

# Remove all services in a group
curl -X POST http://localhost:3000/remove \
-H "Content-Type: application/json" \
-d '{"group": "backend"}'

Add a new server mode to monocore that exposes a REST API for managing services. This allows programmatic control of monocore through HTTP endpoints.

Key changes:
- Add new `serve` subcommand to start monocore in server mode
- Implement REST API endpoints for service management:
  - POST /up - Start services defined in config
  - POST /down - Stop running services
  - GET /status - Get status of all services
  - POST /remove - Remove service files
- Add server configuration with customizable port (default: 3000)
- Update documentation with REST API usage examples and curl commands
- Add server-related types and handlers for request/response processing

The REST API provides the same functionality as the CLI but in a way that can be integrated with other services and automation tools.
@appcypher appcypher merged commit a84956d into main Nov 15, 2024
5 checks passed
@appcypher appcypher deleted the appcypher/monocore-server branch November 15, 2024 00:31
@github-actions github-actions bot mentioned this pull request Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant