Skip to content

doomhound188/rewst-api-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rewst API Server (Go)

A Go-based API server for interacting with Rewst workflows, converted from Node.js.

Requires Go 1.20 or newer.

Project Structure

rewst-api-server/
├── cmd/
│   └── server/
│       └── main.go          # Application entry point
├── internal/
│   ├── handlers/
│   │   └── handlers.go      # HTTP request handlers
│   ├── middleware/
│   │   └── middleware.go    # HTTP middleware (logging, CORS)
│   └── rewst/
│       └── client.go        # Rewst API client
├── go.mod                   # Go module definition
├── go.sum                   # Go module checksums
├── Dockerfile              # Docker container definition
├── docker-compose.yml      # Docker Compose configuration
└── README.md               # This file

Features

  • Workflow Execution: Run Rewst workflows with custom parameters
  • Status Monitoring: Check the status of running workflows
  • Health Checks: Built-in health check endpoint
  • Middleware: Request logging and CORS support
  • Containerization: Docker and Docker Compose support
  • Environment Configuration: Environment variable support with .env files

API Endpoints

Run Workflow

POST /api/workflows/{id}/run

Request body:

{
  "parameters": {
    "key1": "value1",
    "key2": "value2"
  },
  "context": {
    "user_id": "123",
    "organization": "example"
  }
}

Get Workflow Status

GET /api/workflows/{id}/status

Health Check

GET /api/health

Environment Variables

Create a .env file in the root directory:

REWST_API_KEY=your_rewst_api_key_here
PORT=3000

Required:

  • REWST_API_KEY: Your Rewst API key

Optional:

  • PORT: Server port (defaults to 3000)

Installation & Usage

Local Development

  1. Clone the repository

    git clone <repository-url>
    cd rewst-api-server
  2. Install dependencies

    go mod download
  3. Set up environment variables

    cp .env.example .env
    # Edit .env with your Rewst API key
  4. Run the server

    go run cmd/server/main.go

Using Docker

  1. Build and run with Docker Compose

    docker-compose up --build
  2. Or build and run manually

    docker build -t rewst-api-server .
    docker run -p 3000:3000 --env-file .env rewst-api-server

Development

Project Layout

This project follows the standard Go project layout:

  • cmd/: Main applications for this project
  • internal/: Private application and library code
  • internal/handlers/: HTTP request handlers
  • internal/middleware/: HTTP middleware components
  • internal/rewst/: Rewst API client implementation

Building

# Build for current platform
go build -o server ./cmd/server

# Build for Linux (useful for Docker)
CGO_ENABLED=0 GOOS=linux go build -o server ./cmd/server

Testing

# Run tests
go test ./...

# Run tests with coverage
go test -cover ./...

API Usage Examples

Running a Workflow

curl -X POST http://localhost:3000/api/workflows/your-workflow-id/run \
  -H "Content-Type: application/json" \
  -d '{
    "parameters": {
      "input_param": "test_value"
    },
    "context": {
      "user_id": "123"
    }
  }'

Checking Workflow Status

curl http://localhost:3000/api/workflows/your-workflow-id/status

Health Check

curl http://localhost:3000/api/health

Configuration

The server can be configured using environment variables:

Variable Description Default
REWST_API_KEY Rewst API authentication key Required
PORT Server port 3000

Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success
  • 400: Bad Request (invalid JSON, missing parameters)
  • 500: Internal Server Error (API errors, network issues)

Error responses include descriptive messages in the response body.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

[Add your license information here]

About

local api server to run powershell and python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published