// defined a hardcoded users array for the exampleletusers=[{id:'1',name:'John'},{id:'2',name:'Ben'},{id:'3',name:'George'}]functiongetUser(id){// retrieve user operation by idreturnusers.find(function(user){returnuser.id===id;})}functioncreateUser(data){// create user operation which will update the users array only for the scope of the current request call as the users are hardcodedusers.push({id:data.id,name:data.name});}functiondeleteUser(id){// delete user operation which will remove a user only for the current scope of the request as the users are hardcodedusers=users.filter(function(user){returnuser.id!==id})}functionallUsers(){// retrieve all users operationreturnusers;}// get id query param constid=$.request.parameters.get("id");// check the type of the requestswitch($.request.method){case$.net.http.PUT:if($.request.contentType==="application/json"){createUser(JSON.parse($.request.body.asString()));$.response.setBody(`created user [${JSON.stringify($.request.body.asString())}]`);}else{$.response.setBody(JSON.stringify({"error":"Unsupported content type."}));}break;case$.net.http.GET:if(id){letuser=getUser(id);$.response.setBody(JSON.stringify({user:user}));}else{letusers=allUsers();$.response.setBody(JSON.stringify({users:users}));}break;case$.net.http.DELETE:if(id){deleteUser(id);$.response.setBody(`deleted user with id [${id}]`);}else{$.response.setBody(JSON.stringify({"error":`Parameter id is missing`}));}break;default:$.response.setBody(JSON.stringify({"error":`Unsupported method [${$.request.method}]`}));}