Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKirt Perez
7,374 PointsUnderstanding what JSON is in these lectures
Hello all, I am currently trying to figure out exactly why we used JSON in our AJAX module. We are put into a scenario where I am paired with a designer and a developer. The developer deals with the server sided programming and I am left to deal with the front end developing. To my understanding, there are server sided languages such as Ruby, PHP, Python etc. In what way was the server sided programmer being used in this mock example? Is the JSON file the one that is made by the server sided programmer? I understand that JSON is a response format from the server side being sent to the client side. How does the server sided programmer turn a huge database into a JSON file?
1 Answer
Dane Parchment
Treehouse Moderator 11,077 PointsWhoo. That's a lot to unpack there. So let's deal with each of your points or at least what I think are your points:
In what way was the server sided programmer being used in this mock example?
Basically if this were a real-world example the server side programmer would be working on the back-end API that you are connecting to via Ajax.
Is the JSON file the one that is made by the server sided programmer?
Technically yes. The back-end dev would be the one building the response object and sending it as JSON/XML/etc.
How does the server sided programmer turn a huge database into a JSON file?
This is actually a very complex question, you're basically asking how back-end development works. So let's break it down.
- The client sends a request to the server, this is usually by targeting a specific a specific 'endpoint' which is basically a url that the server is listening to for requests.
- The server receives the request from the client and retrieves data, if any, provided.
- Based on the endpoint that the user requested, and the type of request being sent (GET/POST/PUT/DELETE/etc.) the back-end dev will write a function for that endpoint.
- Usually the function will communicate with a database via an sql query or some other alternative.
- The database will return the relevant data and the back-end dev will then form this object into easier to read data (JSON or XML for example) and then send a response back containing that object. Which is the JSON you receive.
This is obviously very simplified and while I could (didn't talk about error handling or statuses for example), I'm not going to provide code examples because they would only lead to further confusion.
Hope that helps, happy coding!