link

PrintCSS

Can I make an asynchronous request?

Yes, asynchronous requests are straightforward! All you need to do is set sync to false in the requests body JSON. Here is an example of how you can do this:

{
    "css": "body { color: red; }",
    "html": "Hello PrintCSS Cloud",
    "options": {
        "sync": "false"
    }
}

To send the request to our API now, you need to subscribe to a plan on RapidAPI. With this, you get the API key that is required to authenticate with our REST service. How to send a request you can see in the "How to create a PDF from my HTML and CSS Code?" article.

The response to such an API request will be a JSON with the pdfid:

{
    "pdfid": "OqE89kpPy7LDdwmLza1YKXAxljVwBJ"
}

To check your PDF rendering request status, you can pass this JSON as a request body to the API. So your request body looks exactly like the response:

{
    "pdfid": "OqE89kpPy7LDdwmLza1YKXAxljVwBJ"
}

As a result, you either get the PDF if the rendering is finished. Or a JSON object telling you your rendering request is still open, in progress, or ran into an error. A sample of such a return can be seen below.

{
    "pdfid": "OqE89kpPy7LDdwmLza1YKXAxljVwBJ",
    "status": "in_progress",
    "message": "PDF rendering is currently in progress"
}

Attached you find the result PDF.

asynchronous rendering (PDF, 6.06 KB)