项目作者: chilupa

项目描述 :
$http methods - get, post
高级语言: JavaScript
项目地址: git://github.com/chilupa/angularjs-http.git
创建时间: 2018-09-18T23:07:29Z
项目社区:https://github.com/chilupa/angularjs-http

开源协议:

下载


angularjs - $http methods

This application utilizes AngularJS $http get, post methods to fetch data from the server and post data to Server.

$http.get()

Syntax:

  1. $http({
  2. method: 'GET',
  3. url: '/someUrl'
  4. }).then(function successCallback(response) {
  5. // this callback will be called asynchronously
  6. // when the response is available
  7. }, function errorCallback(response) {
  8. // called asynchronously if an error occurs
  9. // or server returns response with an error status.
  10. });

$http.post()

Syntax:

  1. $http({
  2. method: 'POST',
  3. url: '/someUrl',
  4. headers: headers: {
  5. 'Content-Type': 'application/json'
  6. },
  7. data: { test: 'test' }
  8. }).then(function successCallback(response) {
  9. // this callback will be called asynchronously
  10. // when the response is available
  11. }, function errorCallback(response) {
  12. // called asynchronously if an error occurs
  13. // or server returns response with an error status.
  14. });

Mock json data:

  1. {
  2. "users": [
  3. {
  4. "id": 1,
  5. "name": "John",
  6. "job": "Software developer",
  7. "location": "Dallas,TX"
  8. },
  9. {
  10. "id": 2,
  11. "name": "Sansa",
  12. "job": "Java developer",
  13. "location": "Irving,OK"
  14. },
  15. {
  16. "id": 3,
  17. "name": "Steve",
  18. "job": "Full stack developer",
  19. "location": "Dublin,OH"
  20. }
  21. ]
  22. }

Used json-server for running the above mock json data file locally in the terminal.

json-server users.json --watch