Simple Standby Actor
Pricing
Pay per usage
Simple Standby Actor
Pricing
Pay per usage
Rating
0.0
(0)
Developer

nm
Actor stats
0
Bookmarked
6
Total users
5
Monthly active users
16 hours ago
Last modified
Categories
Share
Standby Demo Actor
A simple demonstration of Apify Standby Actors that provides a RESTful API for basic math operations and string manipulation.
Overview
This Actor runs in Standby mode, which means it operates as a persistent HTTP server that can handle requests in real-time without the typical Actor startup delay. It's perfect for applications that need fast response times and real-time API functionality.
Features
- ✅ Math Operations: Add two numbers together
- ✅ String Operations: Concatenate two strings
- ✅ OpenAPI Documentation: Full API specification included
- ✅ TypeScript: Written in TypeScript with full type safety
- ✅ Readiness Probes: Proper health check support for Apify platform
API Endpoints
Health Check
- GET
/- Returns a simple greeting message and serves as a health check
Math Operations
- POST
/math/add- Add two numbers together
Request Body:
{"a": 5,"b": 3}
Response:
{"result": 8,"operation": "addition"}
String Operations
- POST
/string/concat- Concatenate two strings
Request Body:
{"str1": "Hello, ","str2": "World!"}
Response:
{"result": "Hello, World!","operation": "concatenation"}
Usage Examples
Using curl
# Health checkcurl https://your-actor-standby-url.apify.app/# Add two numberscurl -X POST https://your-actor-standby-url.apify.app/math/add \-H "Content-Type: application/json" \-d '{"a": 10, "b": 25}'# Concatenate stringscurl -X POST https://your-actor-standby-url.apify.app/string/concat \-H "Content-Type: application/json" \-d '{"str1": "Hello, ", "str2": "Apify!"}'
Using JavaScript/fetch
// Add two numbersconst addResponse = await fetch('https://your-actor-standby-url.apify.app/math/add', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ a: 15, b: 27 })});const addResult = await addResponse.json();console.log(addResult); // { result: 42, operation: "addition" }// Concatenate stringsconst concatResponse = await fetch('https://your-actor-standby-url.apify.app/string/concat', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ str1: "Standby ", str2: "Actors are awesome!" })});const concatResult = await concatResponse.json();console.log(concatResult); // { result: "Standby Actors are awesome!", operation: "concatenation" }
Local Development
-
Install dependencies:
$npm install -
Build the project:
$npm run build -
Run locally (development mode):
$npm run devNote: When running locally, the Actor will detect that it's not in Standby mode and will display an informational message.
Deployment to Apify
-
Install Apify CLI:
$npm install -g apify-cli -
Login to your Apify account:
$apify login -
Deploy the Actor:
$apify push -
Enable Standby mode in the Actor settings in Apify Console.
Project Structure
standby-actor/├── .actor/│ └── actor.json # Actor configuration with OpenAPI schema├── src/│ └── main.ts # Main TypeScript source code├── Dockerfile # Docker configuration├── package.json # Node.js dependencies and scripts├── tsconfig.json # TypeScript configuration└── README.md # This file
Error Handling
The API includes proper error handling for:
- 400 Bad Request: Invalid JSON or missing required fields
- 404 Not Found: Unknown endpoints
- 500 Internal Server Error: Unexpected server errors
Example error response:
{"error": "Both \"a\" and \"b\" must be numbers"}
OpenAPI Specification
This Actor includes a complete OpenAPI 3.0.3 specification embedded in the actor.json file. This allows:
- Automatic API documentation generation
- Client SDK generation
- API testing tools integration
- Better integration with external services
About Standby Mode
Standby mode allows Actors to run as persistent HTTP servers, providing:
- Fast Response Times: No cold start delays
- Real-time Processing: Handle requests immediately
- API-like Behavior: Perfect for microservices and webhooks
- Cost Efficiency: Pay only for actual usage time
This makes Standby Actors ideal for:
- API endpoints and microservices
- Webhook handlers
- Real-time data processing
- Integration services
License
ISC License