Reputation: 3
I have some customers in ArrayList and when I want through Postman delete (with id) it is not working : 500 - Internal Error. Please Could someone help me ?
Delete customer
DELETE http://localhost:8080/api/customers/{customerId}
@DeleteMapping("/api/customers{customerId}")
public void deleteCustomer(@PathVariable Long customerId) {
customers.remove(this.customers.get(Math.toIntExact(customerId)));
}
Upvotes: 0
Views: 115
Reputation: 53
Is this how you send the request?
http://localhost:8080/api/customers/{customerId}
If you are sending like this, it won't work because you gave path like this:
/api/customers{customerId}
In my opinion, either change the path like this:
/api/customers/{customerId}
Or send the request like this:
http://localhost:8080/api/customers{customerId}
Upvotes: 1
Reputation: 481
try like this you did not add "/" in delete mapping.
@DeleteMapping("/api/customers/{customerId}")
public void deleteCustomer(@PathVariable Long customerId) {
customers.remove(this.customers.get(Math.toIntExact(customerId)));
}
Upvotes: 1