This project is a Cloudflare Worker that validates and fetches details for a given GSTIN (Goods and Services Tax Identification Number) using the "knowyourgst.com" service.
- Install Dependencies: Run
npm install
to install the required dependencies. - Development Server: Run
npm run dev
to start a development server. - Deploy: Run
npm run deploy
to publish your worker.
To use the worker, make a GET request to the worker URL with the gstin
query parameter. For example:
https://gstin-validation.devstroop.workers.dev/?gstin=29AAAAA0000A1Z5
- isValidGSTIN(gstin): Validates the GSTIN format.
- getCsrfToken(): Fetches the CSRF token required for making POST requests.
- postGstinDetails(gstin, csrfToken): Posts the GSTIN details to the service and retrieves the response.
- parseGstinDetails(responseBody): Parses the response body to extract GSTIN details.
The worker returns appropriate error messages and status codes for invalid GSTIN formats and failed requests.
Learn more about Cloudflare Workers at Cloudflare Workers Documentation.