0

Normally, AngularJS has reponsibility to consume data from API service or API provider using any XHR method such as $http, $resource, and so on. but I want to use AngularJS acting as API service or API provider on client side. For example

I has JSON data store in AngularJS's variable:

{
    id: 1,
    firstname: "user1"
}

Normal situation:

  1. user type url "http://localhost/#/user" via browser or PostMan(Chrome's Add-on)
  2. The result show (content type "text/html")

    <html>
        <head>
            <script src="...angular.js"></script>
        </head>
        <body>
            <pre>
                {
                    id: 1,
                    firstname: "user1"
                }
            </pre>
       </body>
    </html>
    

Prefer situation and output:

  1. user type url "http://localhost/#/user" via browser or PostMan(Chrome's Add-on)
  2. The result shown (content type "application/json"):

    {
        id: 1,
        firstname: "user1"
    }
    

Does AngularJS can do like my prefer above?

  • Yes, it's possible. But it's not clear, why you need that. – Estus Flask Mar 24 '17 at 01:15
  • @estus Curious... how could you return "application/json" from an AngularJS route? – Ben Mar 24 '17 at 01:18
  • @estus Actually, I implement AngularJS's app for front. And I got requirement that "Provide /monitor endpoint of front-end to monitor 3rd of API provider" My solution: I create /monitor from webserver in order to check 3rd party API provider before response JSON result to client But My collegue don't want to keep "/monitor" on web server. They want to keep in AngularJS'app and return "application/json" same as webserver. Actually, I understand that It might not possible from machanism of AngularJS. However, I might misunderstood. So I want to make sure again from anyone. – ValKyRieQ Mar 24 '17 at 01:29
  • See http://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser for example. Of course, it won't work in Postman. I would suggest to explain to the other party that client-side JS doesn't work this way (not Angular's limitation). – Estus Flask Mar 24 '17 at 01:41
  • @estus Thank you so much for explain. – ValKyRieQ Mar 24 '17 at 02:44

0 Answers0