HTTP Methods in Alamofire

In this lesson

Here is a quick talk about the available HTTP methods in Alamofire and how to access and set those on your requests.

Kyle Roberts
Swift Guru at Large

Kyle's Series

Transcript

Tap on time to skip ahead

0:11

Kyle here with brax.tv and we’re going to talk about using a specific HTTP method in an Alamofire request. And the HTTP method is the first argument in the request initialization method that we can see defined here with Command+click, and it is of type Method, which is an Alamofire custom type. Actually, from here we can Command+click that, and see all of the available options and that it is an enum and each method is going to have a value type of string.

0:45

Now there’s a lot more options than most people ever use. The two most common, I would say, are GET and POST, maybe sometimes DELETE. And here in SteamReader, the only one I’m using is the GET method. And it is as easy as that. And .GET, that’s the same as using Method.GET but, you know, quicker Swift syntax. And in the future, there is any situation where I’m going to be uploading data back to Steam, of course I’ll need to adjust URLs and parameters to add any data I’m actually uploading. But we can just change the type to POST and it’s easy enough to update. You may be thinking, if most of the URL requests going to be making are GET, why do I need to specify that it’s GET anyway? And that’s because there’s no default value here so it’s always expecting a value, and almost all of the time that you’re working with a REST API, you’re going to be able to give the correct HTTP method round the United self. N’t. 

Additional Info

Register to get access to additional resources and info.