function makeAPI(root) { //Protobuf types const AttributeType = 'models.proto.cofd.api.Attribute'; const Attribute = root.lookupType(AttributeType); const SkillValueUpdateType = 'models.proto.cofd.api.SkillValueUpdate'; const SkillValueUpdate = root.lookupType(SkillValueUpdateType); const SkillSpecializationUpdateType = 'models.proto.cofd.api.SkillSpecializationsUpdate'; const SkillSpecializationsUpdate = root.lookupType(SkillSpecializationUpdateType); const protobufContentType = (messageType) => ({ 'Content-Type': 'application/x-protobuf; messageType="' + messageType + '"' }); const attributesResource = (username, characterID) => '/api/cofd/' + username + '/' + characterID + '/attributes'; const skillResource = (username, characterID, skillName) => '/api/cofd/' + username + '/' + characterID + '/skills'; async function updateAttribute(params) { const { username, characterID, attribute, newValue } = params; let req = Attribute.create({ name: attribute, value: parseInt(newValue) }); const resource = attributesResource(username, characterID); let resp = await fetch(resource, { method: 'PATCH', headers: { ... protobufContentType(AttributeType) }, body: Attribute.encode(req).finish() }).then(async resp => { console.log("resp is", await resp.text()); }).catch(async err => { console.log("err is", err.text()); }); } async function updateSkillValue(params) { const { username, characterID, skillName, newValue } = params; let req = SkillValueUpdate.create({ name: skillName, value: parseInt(newValue) }); const resource = skillResource(username, characterID); let resp = await fetch(resource, { method: 'PATCH', headers: { ... protobufContentType(SkillValueUpdateType) }, body: SkillValueUpdate.encode(req).finish() }).then(async resp => { console.log("resp is", await resp.text()); }).catch(async err => { console.log("err is", err.text()); }); } return { updateAttribute, updateSkillValue }; }