Get your API key
To authenticate with the Rapidcron API, you need an API key. You can view and manage your API keys here.
Install the SDK
npm install rapidcron --save
npm install rapidcron --save
Create a job
Start by creating a new instance of the SDK with your API key:
import Rapidcron from "rapidcron";
const rapidcron = new Rapidcron("API_KEY");
And then define a task depending on whether it’s a delayed or recurring task:
await rapidcron.tasks.create({
type: "delayed",
nextRunAt: new Date(Date.now() + 1000 * 60 * 60), // 1 hour from now
request: {
method: "POST",
url: "https://example.com",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
hello: "world"
})
}
});
await rapidcron.tasks.create({
type: "delayed",
nextRunAt: new Date(Date.now() + 1000 * 60 * 60), // 1 hour from now
request: {
method: "POST",
url: "https://example.com",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
hello: "world"
})
}
});
Recurring tasks use cron expressions to define the schedule.
await rapidcron.tasks.create({
type: "recurring",
recurrencePattern: "* * * * *", // Every minute
request: {
method: "POST",
url: "https://example.com",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
hello: "world"
})
}
});