Openwhisk web actions for API backends

Shenavi de Mel
Jun 29, 2018 · 4 min read

Why Serverless for API backends?

Let’s create our API

wsk api create -n "LibraryAPI" /club /books/{isbn} get library/getBooksAction --response-type http -iwsk api create -n "LibraryAPI" /club /books/{isbn} put library/putBooksAction --response-type http -iwsk api create -n "LibraryAPI" /club /books/{isbn} delete library/deleteBooksAction --response-type http -iwsk api create -n "LibraryAPI" /club /books get library/getBooksAction --response-type http -i
wsk api list /club -fok: APIs
Action: library/getBooks
API Name: LibraryAPI
Base path: /club
Path: /books/{isbn}
Verb: get
URL: https://${APIHOST}:9001/api/${GENERATED_API_ID}/club/books/{isbn}
Action: library/getBooks
API Name: LibraryAPI
Base path: /club
Path: /books
Verb: get
URL: https://${APIHOST}:9001/api/${GENERATED_API_ID}/club/books
Action: library/putBooks
API Name: LibraryAPI
Base path: /club
Path: /books/{isbn}
Verb: put
URL: https://${APIHOST}:9001/api/${GENERATED_API_ID}/club/books/{isbn}
Action: deleteBooks
API Name: LibraryAPI
Base path: /club
Path: /books/{isbn}
Verb: delete
URL: https://${APIHOST}:9001/api/${GENERATED_API_ID}/club/books/{isbn}
curl -X PUT https://${APIHOST}:9001/api/${GENERATED_API_ID}/books/harry-potter -k{"message":"The book harry-potter was successfully added"}
curl -X GET https://${APIHOST}:9001/api/${GENERATED_API_ID}/books/harry-potter -k{"message":"Successfully retrieved the document","doc":"{\"_id\":\"harry-potter\",\"_rev\":\"7-8f8aeecee81c43e95dfa68c71c14c5fa\",\"description\":\"This is a sample book\",\"name\":\"harry-potter\"}\n"}
curl -X DELETE https://${APIHOST}:9001/api/${GENERATED_API_ID}/books/harry-potter -k{"message":"Successfully deleted the book harry-potter"}

Let’s sum it up

References

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade