Configuring the $http request in angularjs – quick tip

angularjs‘ built-in $http service is good enough to serve most purposes. angularjs‘ built-in $http has the following methods:

  • $http.get(url, [config]): This is used to get data from the server where:
    • url: This is the absolute or relative URL path of destination request (required)
    • config: This is the configuration object (optional)
  • $http.head(url, [config]): This is used to get the full header information of the request where:
    • url: This is the absolute or relative URL path of destination request (required)
    • config: This is the configuration object (optional)
  • $http.post(url, data, [config]): This is used to post data to server where:
    • url: This is the absolute or relative URL path of destination request (required)
    • data: This is the data needed for post to the server (required)
    • config: This is the configuration object (optional)
  • $http.put(url, data, [config])
    • url: This is the absolute or relative URL path of destination request (required)
    • data: This is the data needs to post to the server (required)
    • config: This is the configuration object (optional)
  • $http.delete(url, [config]): This is used to delete data from the server where:
    • url: This is the absolute or relative URL path of destination request (required)
    • config: This is the configuration object (optional)
  • $http.jsonp(url, [config]): This is used to get JSON data from the server of a different domain where:
    • url: This is the absolute or relative URL path of destination request (required)
    • config: This is the configuration object (optional)
  • $http.patch(url, data, [config])
    • url: This is the absolute or relative URL path of destination request (required)
    • data: This is the data needs to post to the server (required)
    • config: This is the configuration object (optional)

    We can customize the default $http configuration, such as to set the customer header, transform the client request and server response, set timeout instead of default timeout, enable cache and/or set the response type, and so on.

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

Get The best In Web dev

Get The best In Web dev

Join dunebook and recieve best in Angular, React, Vue, Python, Java & more. Directly to your inbox once a week FREE !

You have Successfully Subscribed!

Pin It on Pinterest