DEV Community

Daniel Igel
Daniel Igel

Posted on

Generate EAN-13, Code 128 and QR barcodes via REST API — PNG and SVG output, no library needed

Adding barcodes to an app usually means installing a native library, dealing with font paths, or spinning up a separate service. For a shipping label, product catalog, or inventory export, that setup overhead isn't worth it.

One GET returns a barcode image as raw PNG or SVG bytes:

curl -o barcode.png \
  "https://barcode-generator-api4.p.rapidapi.com/api/v1/barcode?data=012345678905&type=EAN13&format=png" \
  -H "x-rapidapi-key: YOUR_RAPIDAPI_KEY" \
  -H "x-rapidapi-host: barcode-generator-api4.p.rapidapi.com"
Enter fullscreen mode Exit fullscreen mode

The response is the image directly — write it to a file, stream it into an <img src>, or pipe it into your PDF renderer. Pass format=svg for a scalable vector.

For extra control — scale, height, or hiding the human-readable text — switch to the POST endpoint:

const res = await fetch(
  'https://barcode-generator-api4.p.rapidapi.com/api/v1/barcode',
  {
    method: 'POST',
    headers: {
      'content-type': 'application/json',
      'x-rapidapi-key': process.env.RAPIDAPI_KEY,
      'x-rapidapi-host': 'barcode-generator-api4.p.rapidapi.com',
    },
    body: JSON.stringify({ type: 'QR', data: 'https://example.com', format: 'svg', scale: 4 }),
  }
);
const svg = await res.text(); // image/svg+xml
Enter fullscreen mode Exit fullscreen mode

Supported types: EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, Code 93, ITF-14, DataMatrix, QR — powered by bwip-js server-side, no native bindings, no font files to manage.

Need bulk generation? POST /api/v1/barcode/batch accepts up to 20 items and returns each barcode as a base64-encoded image in one JSON response — useful for pre-generating product label sheets.

Free tier on RapidAPI: https://rapidapi.com/danieligel/api/barcode-generator-api4

Which barcode format does your project use most — linear (EAN/Code 128) or 2D (QR/DataMatrix)?

Top comments (0)