0

I've been doing research in order to write an API for a school project, and when referencing the API documentation of YouTube and Twitter, I see API URLs like this

https://api.twitter.com/1.1/account/settings.json

My understanding was that you execute a method on the backend which will return information to the caller, but I thought those files had to be of extension type .py or .java or whatever language you're using, and JSON was just the return type. I've been unable to find any information on how a .json file works in this example. Is there code in settings.json that is being executed?

Boetto
  • 3
  • 2
  • 1
    What you're seeing in the URL you provided is the result of server code rendering data in a specific format from a user's request. Similar to the way server code like python or php is used to send HTML to a browser – roy Apr 23 '17 at 17:24

1 Answers1

1

JSON is just a format of your data, that you can then use, for example in JavaScript.

It is back-end language independent. By this I mean, that front-end of the application does not care who produced .json file.

Maybe it was Java application, maybe it was Python, or PHP application it does not matter. It can be also static file, with fixed content which just has json format.

After you receive such thing in front-end, you can do with it whatever you want. From your perspective it will be probably some kind of nested array.

In example you provided, I get:

{"errors":[{"code":215,"message":"Bad Authentication data."}]}

And it is fine, it's just data you get. It is JSON format - that is true. But you don't care that path has .json in the URL, it could have any extension, what is important is what's inside.

That is a beauty of JSON. You can prepare for yourself static file with mocked data in JSON format, and use it while developing front-end of the application. When you wish, you can have back-end application which will return real data for your app.

You can also see here, how to return json file from PHP: Returning JSON from a PHP Script

Or here to see how to do it in Python (Django Framework): Creating a JSON response using Django and Python

Community
  • 1
  • 1
jedruniu
  • 520
  • 4
  • 13