Created
October 3, 2018 11:05
-
-
Save ThomasPe/54fb8863dcab0e20e18522ccd030a7fc to your computer and use it in GitHub Desktop.
Update | Azure Functions + NodeJs + Table Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const azure = require('azure-storage'); | |
const tableService = azure.createTableService(); | |
const tableName = "mytable"; | |
module.exports = function (context, req) { | |
context.log('Start ItemUpdate'); | |
if (req.body) { | |
// TODO: Add some object validation logic | |
const item = req.body; | |
// Depending on how you want this to behave you can also use tableService.mergeEntity | |
tableService.replaceEntity(tableName, item, function (error, result, response) { | |
if (!error) { | |
context.res.status(202).json(result); | |
} else { | |
context.res.status(500).json({ error: error }); | |
} | |
}); | |
} | |
else { | |
context.res = { | |
status: 400, | |
body: "Please pass an item in the request body" | |
}; | |
context.done(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment