Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best process for fetching new content using JSON?

Tags:

json

php

What would be the best way to fetch new content on a website with json, I got the following system in my mind: (looped)

  • client -> (do i have new content) -> server
  • client <- (nope) <- server
  • client -> (do i have new content) -> server
  • client <- (yes, contentId x) <- server
  • client -> (get content with id x) -> server
  • client <- (Jim Morrison) <- server

Is this the best way? The application will be used for over 10000+ users, how does Facebook do this, and still keep everyone super fast up-to date?

like image 443
randomKek Avatar asked Nov 25 '11 01:11

randomKek


People also ask

How will you fetch the data in JSON?

To get JSON from the server using the Fetch API, you can use the response. json() method. The response. json() method reads the data returned by the server and returns a promise that resolves with a JSON object.

What is JSON in Fetch?

fetchjson. 1 Comments. JSON, which is a simple format of structured data, has become a popular format to send data over the network. Here's an example of JSON containing an object with props and values: json.

What is JSON process?

JavaScript Object Notation, more commonly known by the acronym JSON, is an open data interchange format that is both human and machine-readable. Despite the name JavaScript Object Notation, JSON is independent of any programming language and is a common API output in a wide variety of applications.


1 Answers

One modern way to do this is to use a server-push system like WebSockets or Socket.io rather than a client-pull system like occasionally requesting an "is there something new" status.

With this type of technology there is an open connection from the client (I'm assuming it's a web browser) to the server at all times, and whenever something happens on the server, the server pushes the data out to the client directly.

For code and examples check out http://socket.io/

Not all server-side technology is compatible with this type of approach, but one very good one is Node.js which allows you to write event-driven server-side code in Javascript. See http://nodejs.org

If you choose to use Node.js on the server and want to interact with browsers, there is even Now.js (see http://nowjs.com/ ) which allows you to in effect call functions on the client from the server!

like image 50
nicolaskruchten Avatar answered Oct 23 '22 15:10

nicolaskruchten