JavaScript and JSON Essentials
Sai S Sriparasa, Bruno Joseph D'mello
- 226 páginas
- English
- ePUB (apto para móviles)
- Disponible en iOS y Android
JavaScript and JSON Essentials
Sai S Sriparasa, Bruno Joseph D'mello
Información del libro
Use JSON for building web applications with technologies like HTML, JavaScript, Angular, Node.js, Hapi.js, Kafka, socket.io, MongoDB, Gulp.js, and handlebar.js, and others formats like GEOJSON, JSON-LD, MessagePack, and BSON.
Key Features
- Use JSON with trending technologies like Angular, Hapi.js, MongoDB, Kafka, and Socket.io
- Debug, validate, and format JSON using developer toolkits, JSONLint, and JSON Editor Online
- Explore other JSON formats like GeoJSON, JSON-LD, BSON, and MessagePack
Book Description
JSON is an established and standard format used to exchange data. This book shows how JSON plays different roles in full web development through examples. By the end of this book, you'll have a new perspective on providing solutions for your applications and handling their complexities.
After establishing a strong basic foundation with JSON, you'll learn to build frontend apps by creating a carousel. Next, you'll learn to implement JSON with Angular 5, Node.js, template embedding, and composer.json in PHP. This book will also help you implement Hapi.js (known for its JSON-configurable architecture) for server-side scripting.
You'll learn to implement JSON for real-time apps using Kafka, as well as how to implement JSON for a task runner, and for MongoDB BSON storage. The book ends with some case studies on JSON formats to help you sharpen your creativity by exploring futuristic JSON implementations. By the end of the book, you'll be up and running with all the essential features of JSON and JavaScript and able to build fast, scalable, and efficient web applications.
What you will learn
- Use JSON to store metadata for dependency managers, package managers, configuration managers, and metadata stores
- Handle asynchronous behavior in applications using callbacks, promises, generators, and async-await functions
- Use JSON for Angular 5, Node.js, Gulp.js, and Hapi.js
- Implement JSON as BSON in MongoDB
- Make use of JSON in developing automation scripts
- Implement JSON for realtime using socket.io and distributed systems using Kafka
Who this book is for
If you're a web developer with a basic understanding of JavaScript and want to write JSON data, integrate it with RESTful APIs to create faster and scalable applications, this book is for you.
Preguntas frecuentes
Información
JSON for Real-Time and Distributed Data
- Real-time communication using JSON with Socket.IO
- Setting up the Socket.IO server and its clients
- Introduction to distributed systems using JSON with Apache Kafka
- Installing Apache and implementing the distributed system concepts in a real-time application
Using JSON with Socket.IO
- Designing the board
- Implementing the real-time functionality via the Socket.IO library
Designing the board
//index.html.js
module.exports = `
<!DOCTYPE html>
<html>
<head>
<title>Pin board</title>
</head>
<style>
body{
background-color: #CCB;
}
.card {
/* Add shadows to create the "card" effect */
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
transition: 0.3s;
width: 30%;
background-color:white;
float: left;
margin: 5px;
}
.card:hover {
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
}
.container {
padding: 2px 16px;
}
h4{
text-align: right;
}
textarea{
border: 0; padding: 10px; width: 90%; margin-right: .5%;
float: left;
width : 60%;
}
input{
float : left;
width : 15%;
padding: 15px;
}
button{
padding: 15px;
float: left;
width : 20%;
}
</style>
<body>
<textarea autocomplete="off" id="textData"></textarea><button
id="postButton">Post</button>
<div class="collection">
<div class="card">
<div class="container">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h4><b>John Doe</b></h4>
</div>
</div>
</div>
</body>
</html>
`;
Setting up the Socket.IO server
npm install socket.io --save
const templateData = require('./index.html');
const server = require('http').createServer((req, res) => {
res.setHeader('content-type', 'text/html');
res.end(templateData);
});
const io = require('socket.io')(server);
io.on('connection', function(client) {
client.on('disconnect', function() {
console.log('user disconnected');
});
console.log("connected to realtime data server");
});
server.listen(3400);