Just a quick question how to avoid duplication of code when doing a http post and put of the same form.
say:
// Post new form
function postForm(form){
var data = {
name: form.name
lastName: form.lastName
}
return api.post('jobs', undefined, JSON.stringify(data), 'application/json');
}
// Put save/edit existing (data)
function putForm(form){
var data = {
name: form.name
lastName: form.lastName
}
return api.put('jobs', undefined, JSON.stringify(data), 'application/json');
}
My attempt, but then I don't have access to function form parameter.
var data = {
name: name
lastName: lastName
}
// Post new form
function postForm(form){
return api.post('jobs', undefined, JSON.stringify(data), 'application/json');
}
// Put save edit form
function postForm(form){
return api.put('jobs', undefined, JSON.stringify(data), 'application/json');
}
Not sure if I'm making sense here but hopefully someone will get what I'm trying to do. Basically I don't want to duplicate the var data when calling api post or put.