Hello world! The simple serverless backend example
3 simple steps to create your first serverless backend example
- Create a project with the
coho create
CLI command. - Change to the project directory and install
npm i codehooks-js -s
. - Open
index.js
in your favorite code editor.
import app from 'codehooks-js'
app.get('/hello', async (req, res) => {
console.log("Inside the routehook");
res.json({"message": "Hello world!"});
});
export default app.init();
Deploy the serverless backend example with the coho deploy
CLI command.
Run coho info --examples
to see your API token and cURL examples.
Test API with:
curl https://<PROJECT NAME>.api.codehooks.io/dev/hello -H 'x-apikey: <API TOKEN>'
Test the serverless backend example:
curl https://mybackendproject-x23a.api.codehooks.io/dev/hello -H 'x-apikey: 6e111ea6-6b3a-412d-8f6b-061c816c67c8'
tip
By clicking the "Import" button in Postman and pasting in the cURL expression, you can test the serverless backend example there.