Eshwar Prasad Yaddanapudi's

passionate and curious software engineer

cURL commands every Beginner Software Engineer should Know

Leave a Comment


Problem statement

 cURL is a frequently used term with in software engineering and especially if you are a backend developer. Irrespective of which piece of software development life cycle (SDLC) you deal with or what language use build apps and platforms on, as a beginners, cURL is always intruging to start. Today we will go through a few basic commands of cURL you should learn on DAY-0 of your journey as a software Engineer. Let's jump right in - 

Introduction

cURL stands of client-URL is a command line tool (CLI), meaning, something that you use inside a terminal. It is a tool used for transfering data between URLs using terminal.

If this is confusing, just ask yourself, how would I invoke an API on a server to get data for an employee given an employeeID?

As per my application document, you need to invoke https://mycompanyuri/employee/id and pass employeeID: 108623.

To do this, most of us these days use Postman or Insomnia a GUI tool. Before these GUI tools were given to developers/engineers, cURL was the go to tool. 

So, you need to do - inside your terminal - curl -X GET https://mycompanyuri/employee/108623 and these would return you data. 

GET requests to a server

An example using https://jsonplaceholder.typicode.com/

curl -X GET https://jsonplaceholder.typicode.com/todos/1 



POST a JSON to server


to post a json to server, we would use the same json placeholder api which is publicly available.





but most of the times, we do not keep typing our json data file in the CLI and rather have a file which want to post to the server. In such a case, cURL gives us an argument to let it know to read the file and it is "@" symbol before the file. 

Assuming you have a file named testdata.json file which holds the data and assuming you are invoking from the terminal (in my case, i am in the same directory as the file while sending it to the server)

gist: 



sample urls i used are from: https://jsonplaceholder.typicode.com/guide/

more about curl: https://curl.se/docs/tooldocs.html

list curl commands dev's generally use: https://gist.github.com/subfuzion/08c5d85437d5d4f00e58 



Previous PostOlder Post Home

0 comments:

Post a Comment