From the course: Android Development: Retrofit with Java

Methods for writing - Android Tutorial

From the course: Android Development: Retrofit with Java

Start my 1-month free trial

Methods for writing

- [Instructor] DELETE is pretty straightforward, - [Instructor] DELETE is pretty straightforward, - [Instructor] DELETE is pretty straightforward, so let's get that out of the way first. so let's get that out of the way first. so let's get that out of the way first. This method should do exactly what it says it does, This method should do exactly what it says it does, This method should do exactly what it says it does, you delete the resource at the target address. you delete the resource at the target address. you delete the resource at the target address. It is important to note that it does not require a body It is important to note that it does not require a body It is important to note that it does not require a body to be present in the request, to be present in the request, to be present in the request, just like the GET and HEAD methods. just like the GET and HEAD methods. just like the GET and HEAD methods. The POST and PUT methods however, The POST and PUT methods however, The POST and PUT methods however, are used to modify or create data on the server. are used to modify or create data on the server. are used to modify or create data on the server. Aside from a difference in verb, Aside from a difference in verb, Aside from a difference in verb, these two methods are fundamentally different these two methods are fundamentally different these two methods are fundamentally different from the GET and HEAD methods from the GET and HEAD methods from the GET and HEAD methods because a message body is usually expected. because a message body is usually expected. because a message body is usually expected. The message body is then used to describe The message body is then used to describe The message body is then used to describe the desired state of an existing object, the desired state of an existing object, the desired state of an existing object, a new object that needs to be created, a new object that needs to be created, a new object that needs to be created, or the parameters needed for a procedure to execute. or the parameters needed for a procedure to execute. or the parameters needed for a procedure to execute. For example, when creating a new comment on a gist For example, when creating a new comment on a gist For example, when creating a new comment on a gist on GitHub, which we will do later on in the course, on GitHub, which we will do later on in the course, on GitHub, which we will do later on in the course, the request might look like this, the request might look like this, the request might look like this, and the response might look like this. and the response might look like this. and the response might look like this. Now PUT and POST are not interchangeable, Now PUT and POST are not interchangeable, Now PUT and POST are not interchangeable, they don't have the same kind of relationship they don't have the same kind of relationship they don't have the same kind of relationship that GET and HEAD do. that GET and HEAD do. that GET and HEAD do. The PUT method is used to set the state The PUT method is used to set the state The PUT method is used to set the state of a specific record. of a specific record. of a specific record. If the record does not exist it will be created, If the record does not exist it will be created, If the record does not exist it will be created, if it does exist it might be updated if it does exist it might be updated if it does exist it might be updated depending on how the API is designed. depending on how the API is designed. depending on how the API is designed. The POST method is used to create a record The POST method is used to create a record The POST method is used to create a record and let the server define its ID, and let the server define its ID, and let the server define its ID, or execute some predefined procedure. or execute some predefined procedure. or execute some predefined procedure. Think of it like, you are putting data into a location, Think of it like, you are putting data into a location, Think of it like, you are putting data into a location, or you are posting a message to the server. or you are posting a message to the server. or you are posting a message to the server.

Contents