Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jan 13 #16

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions MainController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;(function () {
angular.module('fetchApp').controller('MainController', function ($scope, requestService, Response) {
$scope.responses = [];
$scope.url = "http://httpstat.us/200";



$scope.fetch = () => {
const initialDate = (new Date()).getTime();
if($scope.method == "GET"){
requestService.get($scope.url).then((success) => {
const receiveDate = (new Date()).getTime();
const response = new Response(success);
const responseTime = receiveDate - initialDate;
response.responseTime = responseTime;
console.log(responseTime);
$scope.responses.push(response);
}, (error) => {
debugger
});
} else if($scope.method == "POST"){
requestService.post($scope.url).then((success) => {
const receiveDate = (new Date()).getTime();
const response = new Response(success);
const responseTime = receiveDate - initialDate;
response.responseTime = responseTime;
$scope.responses.push(response);
}, (error) => {
debugger
});
} else if($scope.method == "HEAD"){
requestService.head($scope.url).then((success) => {
const receiveDate = (new Date()).getTime();
const response = new Response(success);
const responseTime = receiveDate - initialDate;
response.responseTime = responseTime;
$scope.responses.push(response);
}, (error) => {
debugger
});
} else if($scope.method == "OPTIONS"){
requestService.options($scope.url).then((success) => {
const receiveDate = (new Date()).getTime();
const response = new Response(success);
const responseTime = receiveDate - initialDate;
response.responseTime = responseTime;
$scope.responses.push(response);
}, (error) => {
debugger
});
}
};



});
})();
4 changes: 4 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

;(function () {
const app = angular.module('fetchApp', []);
})();
41 changes: 41 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en" ng-app="fetchApp">
<head>
<meta charset="utf-8">
<title>OMG app</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>

</head>

<body ng-controller="MainController">
{{message}}
<div class="sixteen columns">
<div class="four columns offset-by-four">
<input type="text" name="URL" ng-model="url">
<select ng-model="method">
<option value='GET' >GET</option>
<option value='POST' >POST</option>
<option value='OPTIONS' >OPTIONS</option>
<<option value='HEAD' >HEAD</option>
</select>
<button ng-click="fetch()">Fetch</button>
<ul ng-repeat="response in responses">
<li>
{{response.statusCode}}
{{response.methodName}}
{{response.urlName}}
{{response.size}}
{{response.bites}}
</li>
</ul>
</div>
</div>

<script src="app.js"></script>

<script src="/mainController.js"></script>
<script src="/requestService.js"></script>
<script src="/responseFactory.js"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions requestService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

;(function () {
angular.module('fetchApp').service('requestService', function ($http) {
this.get = url => $http.get(url);
this.post = url => $http.post(url);
this.head = url => $http.head(url);
this.options = url => $http.options(url);
});
})();


// this.get = function (url) {
// return $http.get(url);
13 changes: 13 additions & 0 deletions responseFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;(function () {
angular.module('fetchApp').factory('Response', function () {
const Response = function (responseData) {
this.statusCode = responseData.status;
this.methodName = responseData.config.method;
this.urlName = responseData.config.url;
this.size = (responseData.data.length)/1000;
this.bites = responseData.size;
console.log(responseData);
};
return Response;
});
})();