Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //the HTTP request body contains
- [
- {"code":"C342","description":"PIZZA CARBONARA XXL","price":8},
- {"code":"C324","description":"PIZZA PEPPERONI, MUSHROOMS AND CHEESE","price":12},
- {"code":"C333","description":"4 SEASONS PIZZA","price":9}
- ]
- //in the controller declaration
- [MVCDoc('Creates new articles from a list and returns "201: Created"')]
- [MVCPath('/bulk')]
- [MVCHTTPMethod([httpPOST])]
- procedure CreateArticles(Context: TWebContext);
- //in the implementation section
- procedure TArticlesController.CreateArticles(Context: TWebContext);
- var
- lArticles: TObjectList<TArticle>;
- lArticle: TArticle;
- begin
- lArticles := Context.Request.BodyAsListOf<TArticle>;
- try
- for lArticle in lArticles do
- begin
- GetArticlesService.Add(lArticle);
- end;
- Render(201, 'Articles Created');
- finally
- lArticles.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement