बारकोड वेब सेवाएं: REST, GraphQL और Webhook पैटर्न
API design patterns for barcode services — RESTful barcode lookup, GraphQL product queries, and webhook-based scan event streaming.
Barcode Web Services: REST APIs for Barcode Operations
Web services enable applications to generate, validate, and look up barcode data over HTTP. Whether you are building a web application, mobile app, or integrating systems, barcode REST APIs provide a clean interface for barcode operations.
Common API Operations
Barcode Generation
Generate barcode images from data:
POST /api/v1/barcodes/generate
{
"data": "5901234123457",
"symbology": "ean-13",
"format": "svg",
"width": 200,
"height": 100
}
Response: Barcode image (SVG, PNG, or PDF)
Data Validation
Validate barcode data without generating an image:
POST /api/v1/barcodes/validate
{
"data": "5901234123457",
"symbology": "ean-13"
}
Response: Validation result with check check digit to confirm data integrity." data-category="Check Digit & Validation">digit verification, format compliance, and any errors.
GTIN Lookup
Look up product information by GS1 Standards & Identifiers">GTIN:
GET /api/v1/products/gtin/05901234123457
Response: Product name, description, manufacturer, category, images.
API Design Principles
Symbology as parameter: Accept the symbology name as a parameter rather than having separate endpoints per format. This simplifies the API surface and makes it extensible.
Multiple output formats: Support SVG (for web display), PNG (for embedding), PDF (for printing), and ZPL (for thermal printers) through content negotiation or a format parameter.
Batch endpoints: Provide a batch endpoint for generating or validating multiple barcodes in a single request:
POST /api/v1/barcodes/generate/batch
{
"items": [
{"data": "5901234123457", "symbology": "ean-13"},
{"data": "BATCH001", "symbology": "code-128"}
]
}
Authentication and Rate Limiting
- Use API keys or OAuth 2.0 for authentication
- Implement rate limiting per API key (e.g., 100 requests/minute for generation, 1,000 for validation)
- Log all requests for usage tracking and abuse detection
- Return standard HTTP status codes (400 for invalid data, 429 for rate limit exceeded)
GS1 Data Services
For applications that need GS1 data:
- GS1 Registry Platform: Official API for GTIN verification and product data
- GEPIR: Global Electronic Party Information Registry for company prefix lookup
- GS1 Digital Link Resolver: Resolves GS1 Digital Link URIs to product information
Caching Strategy
Barcode images are deterministic (same input always produces the same output), making them excellent candidates for caching:
- Cache generated images with the data + symbology + format as the cache key
- Set long TTL (hours or days) for generated images
- Use a CDN for frequently requested barcodes
- Cache validation results for shorter periods (minutes) since master data may change
Error Responses
Return structured error responses:
{
"error": "INVALID_CHECK_DIGIT",
"message": "Expected check digit 7, calculated 3",
"field": "data",
"details": {
"provided": "5901234123453",
"expected_check_digit": "7"
}
}