Tutorials , code & Inspiration

Configuring the $http request in angularjs – quick tip

1

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.

prevChapter 1 of 3

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.

You might also like More from author
1 Comment
  1. […] security layer in an AngularJS application, or any other JavaScript application for that matter. Security should always be implemented on the backend services where the data resides. That is the only safe […]

Leave A Reply

Your email address will not be published.

Pin It on Pinterest

Shares