question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] All requests are GET, what about Post?

See original GitHub issue

TL;DR: How to use POSTinstead of GET?

Thanks for your effort, really great learning experience browsing your code. But I have small question.

What I’ve noticed that all requests in GithubService are GET type. By using the abstract class NetworkBoundResource to load each object by overriding createCall() in its Repository, like UserRepository#loadUser(String login).

In Post, I update data remotely on server which I might have instance of it locally with Room, What/How to update Room depending on the API? Is the same class, NetworkBoundResource, is applicable with POST requests? What is the best scenario in this case?

Thanks!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SergeiVasilenkocommented, Jul 31, 2017

NetworkBoundResources is not applicable with POST request for me. I created similar class with follow difference:

@MainThread
ChangeAction(AppExecutors appExecutors) {
    mAppExecutors = appExecutors;
    makeChange();
}

private void makeChange() {
    LiveData<ApiResponse<RequestType>> apiResponse = createCall();
    apiResponse.observeForever(response -> {
        if (response.isSuccessful()) {
            mAppExecutors.diskIO().execute(() -> {
                saveCallResult(processResponse(response));
                mAppExecutors.mainThread().execute(() -> {
                    mResult.addSource(loadFromDb(), newData -> mResult.setValue(Resource.success(newData)));
                });
            });
        } else {
            onChangeFailed();
            mResult.addSource(loadFromDb(), newData -> mResult.setValue(Resource.error(response.error, newData)));
        }
    });
}

Be careful! I didn’t test this code, and it may have bugs.

0reactions
plaboncommented, Sep 28, 2020

@dlam No i was asking about using NetworkBoundResources How can I put data in local database and post the data to server?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GET vs POST - Difference and Comparison | Diffen
HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all...
Read more >
Why are HTTP requests called "get" and "post"? - Stack Overflow
Get request is used to get data from server where as POST request is used to post data to server. GET requests a...
Read more >
Why can't we use POST method for all requests? [closed]
As POST is not idempotent, major browser will warn you if you send twice the same POST request which is not desirable in...
Read more >
Why don't we use POST for all requests and ignore GET?
GET requests are "typically" faster because of caching and the fact that POST sends more data over the wire (see also point 5...
Read more >
HTTP Request Methods – Get vs Put vs Post Explained with ...
In this article, we'll be discussing the get, put, and post HTTP methods. You'll learn what each HTTP method is used for as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found