0

I am trying to make an e-commerce mobile application and the backend for that is built in Spring boot with JPA. now I need to send a delete request to my server from the app. I can't use the primary key for that purpose. I need to delete them by name or email.

the normal delete URL for delete request will look something like this

https:localhost:8080/api/customers/1 

but in my case, I need to delete the customers based on the email not by id my Jpa code looks like this

public interface CustomerRepository extends JpaRepository<Customer, Integer> {

@Transactional
@RestResource(exported = true)
List<Customer> deleteByEmail(String email);

// the url will look something like this: http://localhost:8080/api/customers/search/findByEmail?customer_email=thekopsfc.sd@gmail.com
Customer findByEmail(@Param("customer_email") String email);

}

how could I send a delete request to the server?

javaNoob
  • 68
  • 1
  • 8
  • Can you find customer by email? – MxWild Dec 27 '19 at 12:48
  • @MxWild yes... i used same for delete but it doesn't seem to work.. i would gladly provide additional code if you can help.. the request url looked like this http://localhost:8080/api/customer/search/findByEmail?email=helloworld@gmail.com – javaNoob Dec 27 '19 at 12:51
  • Can you share the code for findByEmail? And how you make call to it? – miyav miyav Dec 27 '19 at 12:55
  • @miyavmiyav i have edited the question please do check – javaNoob Dec 27 '19 at 12:59
  • On the backed you does have a controller with @DeleteMapping("customers/{email}") {service.deleteByEmail(email);} And than you can get this url. – MxWild Dec 27 '19 at 13:01
  • See your findByEmail methodhas \@Param annotation so that it checks for value after ?customer_email= Other way to use it you can use path params like the comment above here are some examples: https://stackoverflow.com/questions/11552248/when-to-use-queryparam-vs-pathparam Also another way is \@RequestBody but DELETE doesnt use that your delete method doesnt provide anything like that unless I'm not completelty sure what \@RestResource annotation does (not using springboot that much – miyav miyav Dec 27 '19 at 13:06

0 Answers0