Supercharge Your Workflow with cURL | Understanding The cURL Command-Line Tool

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back to lenode in today's video we're going to see some examples of the curl command but not just any examples we're going to see examples of interacting with a restful API via curl and the curl command itself is one of the more popular commands out there it stands for client URL and what it is is a data transfer application it consists of two components the lib curl client-side library and the curl command line tool itself curl was originally designed to allow Linux IRC users to automate common tasks however it's now available for most operating systems and behave similarly across platforms the curl application itself is free and open source it's portable across operating systems and it also contains apis or bindings for over 50 programming languages including but not limited to C C plus plus Java and python in this video what I'm going to do is show you some examples of the syntax of the curl command for interacting with rest apis it's actually one of the things that shows you just how powerful the curl command is so let's get right into it [Music] so let's check out some examples of curl in action first of all we need to make sure that we actually have it installed so for that we could type which and then curl in my case I do have it installed if you don't have it installed on your end you could just use your distributions package manager to get this installed I'll leave that up to you but a Quick Command that I can give you is sudo apt install curl if you don't have this on a Debian or Ubuntu system then this is the command right here to get Curl installed but if you're using a different distribution again just use your distros package manager to install curl and then we can continue so let's see some examples the most basic usage of the curl command is to pull something from an actual website so for example what I'll do is type https just need a URL to try as an example here and randomly I'm not really sure why but I thought of kernel.org that's actually where Linux source code can be downloaded from something that you might want to bookmark in case you need it later but anyway I'll press enter and we have the code for that particular website displayed in our terminal so the curl command actually worked Now by default the curl command is going to display the output right there in our terminal but what we could also do is actually output that to a file if that's something that we wanted to do so an example of that is curl with the option Dash o for output and what we're going to do is just save it locally as source.html then we'll need a URL of some kind to show this example with I'll just use the exact same URL again and if I list the storage of my current working directory we can see right there that we have source.html if we count the contents of that we should see the same information and we do now if you're not sure what to do the curl command has a help menu of its own which you can access by using the option dash dash help that gives you some of the options that you could use with the curl command so we can see that there's a silent mode you can also see the version information which is Dash capital V just like that but if you ever need a quick cheat sheet for the curl command then here you go now at this point I'm going to show you some additional examples of curl and these examples are going to show you how to use it with a rest API which is one of the many things that you could do with the curl command now in order for you to access a real server you're going to need well a real server with something on the other end that's going to give you some output whenever you run the curl command so what I'm going to do on my end is give you some examples but if you don't have a website that you can use with curl for your examples you could just write these down as notes because these are helpful examples to have available now what I'm going to do is just type A hypothetical website here and this is an example of the get operation that allows the curl command to receive information from a rest API and in this case I'm not actually clarifying that I want to get information but by default it's going to use the git operation so I really don't need to specify that because if I don't specify anything at all then it just assumes that I want to get information and if I was to run this particular command here against this hypothetical website it would give me some Json information that is served by that website perhaps in this case it would be a list of employees now if there was a particular entry that you wanted to view if you know the instance number you can enter that right here in this case this might be the employee number so randomly just type 10 but you get the idea it's slash and then a number and that number is actually the ID number so it's the URL slash and then an ID in this case to pull that information down now let's see an example of how to post information with the curl command so again for this particular example we'll type curl and the Dash D option allows us to provide an argument that's going to be the data that we want to push to a rest API it should be in a format that matches the targets format but anyway I'll give you an example string that'll show you how the Syntax for the command would look like if you were to run this against a real server and here's the entire command so next we're going to look at the post verb which allows users to push data to a rest API and add new entries to the remote database the data is specified as an argument for the Dash D option and the data should be in a format that matches the targets format so what you're seeing here is an example command if we have the dash H option it's in uppercase and what that option does is it informs the server that the data is in the application slash Json format in this case the dash H option is informing the server that the format of the information is going to be in the Json format if you don't include the dash H option like I'm doing here that actually could result in some unexpected behavior for example the accrual command might add a new header that would confuse some web servers so we definitely want to make sure that we include the dash H option when we can now another example of syntax that I would like to provide you with is an example of how to put information or modify information and that could be a bit confusing right I mean post allows you to add a new entry which you could assume allows you to put a new entry under the server but actually what it's for in this example here is going to be to modify the entry on the target server and the syntax to do something like that would look something like this in this case the Dash D flag specifies the updated information for the record and dash Capital H indicates the data format just like last time however the ID of the record to update must be included as part of the URI where I put command the dash X option must include the keyword so in this case we have Dash capital x and then put right there near the end of the command now another syntax example that I'm going to give you is an example of how to delete information and here's what that looks like and this Command right here is actually simpler I mean we're deleting something so there's not a whole lot that we need to specify we have Dash capital x here with the keyword of delete in all caps that's telling the server on the other end that we want to delete something and at the end of the URL we have ID 31. so what this command is telling the server on the other end is that the data that's associated with ID number 31 we want to delete that and if it's successful we'll get a message back letting us know that it was deleted now there's going to be additional examples in the documentation page that matches this video so go ahead and check that out for more curl fun in the meantime thank you so much for watching this video I really appreciate it if this video was helpful to you then please click that like button that would really help us out and I'll see you in the next video there's some awesome content coming and I can't wait to show you so I'll see you again very soon [Music] thank you [Music]
Info
Channel: Akamai Developer
Views: 88,814
Rating: undefined out of 5
Keywords: linode, linux, linux server, open source, sysadmin, learn linux, linux command line, command line, curl linux, curl, linux command line tutorial, linux tutorial, command line tutorial, learn linux tv, linux commands, command line interface, linux for beginners, command line tools, linux terminal, linux tutorial for beginners, how to use command line, linux operating system, terminal, how to learn linux, command line course, command line tips, curl linux command
Id: -nnJ82uc2ic
Channel Id: undefined
Length: 9min 14sec (554 seconds)
Published: Wed May 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.