Skip to content

Instantly share code, notes, and snippets.

@feliperohdee
Last active May 24, 2017 01:00
Show Gist options
  • Save feliperohdee/4ceaf00db3b27c4564cc0df193c04db7 to your computer and use it in GitHub Desktop.
Save feliperohdee/4ceaf00db3b27c4564cc0df193c04db7 to your computer and use it in GitHub Desktop.
POC

Hey man!

I just have created a small POC (proof of concept) of a simple API to create scheduled triggers and receive postbacks with their relative payloads. I'll explain how it works and afterwards, I want to heard your opinion, ok?

The API is pretty simple and straighforward,

	//resources
	POST https://apis.smallorange.co/cron/triggers
	PUT https://apis.smallorange.co/cron/triggers/:id
	
	// body
	{
	  schedulerMode: 'relative' | 'absolute',
	  schedulerValue: 1, // schedulerMode === 'relative' ? value in minutes : 'absolute timestamp' 
	  payload: {a: 1}, // any object which will be the postback's body
	  repeatInterval: 1 | null, // value in minutes to repeat the trigger
	  repeatTimes: 5 | null, // times to repeat the trigger
	  repeatUntil: null, // absolute timestamp to determine maximum TTL
	  url: 'https://requestb.in/uq74wzuq', // url to post when the trigger have runned
	}

Live sample:

	// See postbacks at:
	// https://requestb.in/uq74wzuq?inspect

	curl -X POST \
	  https://apis.smallorange.co/cron/triggers \
	  -H 'authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lc3BhY2UiOiJ0ZXN0Iiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNDk1NTg2NTg4fQ.p_I_vIFR0i6_XUVOk3Q3XRFYWqA0li_iwij7YEfrOKA' \
	  -H 'cache-control: no-cache' \
	  -H 'content-type: application/json' \
	  -d '{
		"url": "https://requestb.in/uq74wzuq",
		"schedulerValue": 1,
		"repeatTimes": 10,
		"repeatInterval": 1,
		"payload": {
			"hey": "there"
		}
	}'

	curl -X PUT \
	  https://apis.smallorange.co/cron/triggers/cj31yc6m8000001p2c26w3r3a \
	  -H 'authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lc3BhY2UiOiJ0ZXN0Iiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNDk1NTg2NTg4fQ.p_I_vIFR0i6_XUVOk3Q3XRFYWqA0li_iwij7YEfrOKA' \
	  -H 'cache-control: no-cache' \
	  -H 'content-type: application/json' \
	  -d '{
		"url": "https://requestb.in/uq74wzuq",
		"schedulerValue": 1,
		"repeatTimes": 5,
		"repeatInterval": 1,
		"payload": {
			"hello": "world"
		}
	}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment