Say i have a Rest API that has a POST and GET method.
If i want to overwrite a resource in the API i can call the GET method to get the original item and then call the POST method to replace that resource after i am done modifying it.
Should i add the update functionality to the client class like in the first approach or should i make a new class and add the update functionality there and call the client class externally like in the second approach
First approach
class BookApiClient{
Client restClient = ClientBuilder.newClient();
public Book getBook(String id){
// code to get book using rest client
}
public void postBook(){
//code to post a book
}
public void updateBookTitle(String id, String newTitle){
Book book = getBook(id);
book.setTitle(newTitle);
postBook(book);
}
}
Second approach
class BookUpdater{
BookApiClient bookService;
public BookUpdater(BookApiClient bookService){
this.bookService = bookService;
}
public void updateBookTitle(String id, String newTitle){
Book book = bookService.getBook(id);
book.setTitle(newTitle);
bookService.postBook(book);
}
}
Would it be a violation of single responsibility principle to add the updateBookTitle method to the client class or have that as a different like in the second approach