REST API does not support interactive program execution - you have to send all the required input along with the program which is good for some use cases (similar to the non-interactive mode in JDoodle.com). With Websocket API, you can provide an interactive experience to the user like they run a program in their local machine (similar to interactive mode in JDoodle).
How can I make a Websocket call?
Running a WebSocket API is a two-step process.
Get auth token from JDoodle by passing by calling https://api.jdoodle.com/v1/auth-token endpoint with your Client ID/Secret. The token is valid for 180 seconds. You need to make this call from your server to JDoodle.
Using the token you received in step 1, will call WebSocket Endpoint from the browser to provide an interactive experience to the user.
WebSocket call flow
Input Parameters for the "get-token" API call
Output Parameters for the "credit-spent" API call when the execution is successful
The response contains the token in the body.
Output Parameters for the "credit-spent" API call when the execution failed
Integrating WebSocket requests to your Website
Below is a sample implementation of WebSocket in a standalone HTML file. This is pretty much self-explanatory. You have to replace the token with the token you receive in the "auth-token" request.