Web Services UNIT 2 N
Web Services UNIT 2 N
HTML is the standard markup language used to create the structure of web pages.
It consists of elements represented by tags, defining the various parts of a webpage
like headings, paragraphs, images, links, and more.
CSS is used to style and format HTML elements. It controls the layout,
appearance, and responsiveness of a website. With CSS, you can define colors,
fonts, spacing, and the overall visual presentation.
JavaScript:
Web Browsers:
With the variety of devices used to access the web, it's essential to design websites
that adapt to different screen sizes. Responsive web design ensures a consistent
user experience on desktops, tablets, and mobile devices.
APIs allow different software systems to communicate with each other. Web
developers often use APIs to integrate third-party services or to enable
communication between the front end and back end of a web application.
Version Control:
Version control systems like Git are crucial for tracking changes in code,
collaborating with other developers, and rolling back to previous versions if
necessary.
Web Security:
Learning how to deploy a website to a server and manage hosting is a key part of
web development. This involves understanding servers, domains, and services like
AWS, Heroku, or Netlify.
Optimizing websites for search engines ensures that they rank well in search
results. This involves using relevant keywords, creating quality content, and
adhering to SEO best practices.
Data Types:
Variables can hold different types of data, such as numbers, strings (text), booleans
(true/false), objects, arrays, and more. Understanding data types is essential for
working with variables effectively.
// Declaration
let number;
// Initialization
number = 10;
Scope:
Variables can have different scopes, such as global scope or local scope. Global
variables are accessible throughout the entire program, while local variables are
confined to a specific block or function.
function exampleFunction() {
console.log(globalVariable); // Accessible
console.log(localVariable); // Accessible
console.log(globalVariable); // Accessible
Dynamic Typing:
Constants:
In addition to variables, JavaScript allows the declaration of constants using the
const keyword. Constants cannot be reassigned once they are initialized.
const pi = 3.14;
It's good practice to follow naming conventions when creating variables. Variable
names should be descriptive, meaningful, and follow a consistent style. Common
conventions include camelCase (e.g., myVariable) or snake_case (e.g.,
my_variable).
Hoisting:
JavaScript has a concept called hoisting, which means that variable and function
declarations are moved to the top of their containing scope during the compilation
phase. However, only the declarations are hoisted, not the initializations.
var x = 5;
Web Server:
Web server is a program which processes the network requests of the users and
serves them with files that create web pages. This exchange takes place using
Hypertext Transfer Protocol (HTTP).
Basically, web servers are computers used to store HTTP files which makes a
website and when a client requests a certain website, it delivers the requested
website to the client. For example, you want to open Facebook on your laptop
and enter the URL in the search bar of google. Now, the laptop will send an
HTTP request to view the facebook webpage to another computer known as the
web server. This computer (web server) contains all the files (usually in HTTP
format) which make up the website like text, images, gif files, etc. After
processing the request, the webserver will send the requested website-related
files to your computer and then you can reach the website.
Apache HTTP server:
It is the most popular web server and about 60 percent of the world’s web server
machines run this web server. The Apache HTTP web server was developed by
the Apache Software Foundation. It is an open-source software which means that
we can access and make changes to its code and mold it according to our
preference. The Apache Web Server can be installed and operated easily on
almost all operating systems like Linux, MacOS, Windows,
Jigsaw Server: Jigsaw has been written in the Java language and it can run CGI
(common gateway interference) scripts as well as PHP programs. It is not a full-
fledged server and was developed as an experimental server to demonstrate the
new web protocols. It is an open-source software which means that we can
access its code and add changes to it according to our needs and then upload our
own module (the changed code). It can be installed on any device provided that
the device supports Java language and modifications in Java.
Sun Java System: The Sun Java System supports various languages, scripts, and
technologies required for Web 2.0 such as Python, PHP, etc. It is not an open-
source software and therefore its code is inaccessible which means that we
cannot make changes in the code to suit our needs.
Processing Forms
Form Processing is a process by which one can catch data that went into
information fields and convert it into a piece of electronic information or data.
Use the HTML <form> element to create a form on your web page. Inside
the form, use various input elements like text fields, checkboxes, radio
buttons, and buttons to collect user input.
The action attribute specifies the URL to which the form data will be
submitted, and the method attribute defines the HTTP method (e.g., GET
or POST) to be used.
<form action="/submit" method="post">
<label for="username">Username:</label>
<label for="password">Password:</label>
</form>
When the user clicks the submit button, the form data is sent to the server
according to the specified action and method.
4. Server-side Processing:
On the server side, use a server-side scripting language like PHP, Python,
Node.js, or others to handle the form data.
Retrieve form data from the request. The method used to retrieve data
depends on the server-side technology.
Example in Node.js (using Express.js):
});
app.listen(PORT, () => {
});
5. Server-side Validation:
After processing the form, the server sends a response back to the client.
This response can include a confirmation message, a redirection, or an
error message.
Provide feedback to the user about the success or failure of the form
submission. This can be done by displaying messages on the web page or
redirecting to a different page.
9. Security Considerations:
By following these steps, you can create and process forms on the web securely
and efficiently. Keep in mind that the specific implementation details may vary
based on the server-side technology you are using.
Setting Response Headers
res.set({
'Content-Type': 'text/plain',
});
// Send the response
res.send('Hello, World!');
});
app.listen(3000, () => {
});
2. PHP:
In PHP, you can set response headers using the header() function.
phpCopy code
<?php
header('Content-Type: text/plain');
// Output content
?>
3. Python with Flask:
In a Flask application, you can set response headers using the response object.
pythonCopy code
app = Flask(__name__)
@app.route('/example')
def example():
response.headers['Content-Type'] = 'text/plain'
return response
if __name__ == '__main__':
app.run(debug=True)
4. Django (Python):
In Django, you can set response headers using the HttpResponse object.
pythonCopy code
def example_view(request):
response['Content-Type'] = 'text/plain'
return response
javascriptCopy code
app.use(helmet());
res.send('Hello, World!');
});
app.listen(3000, () => {
});
Important Considerations:
Client-Side State:
1. Cookies:
4. IndexedDB:
2. Redux:
Commonly used with React, but can be used with other libraries or
frameworks.
3. VueX:
Server-Side State:
1. Session Management:
2. Databases:
3. Server-Side Caching:
Hybrid Approaches:
Tokens that can carry information and are often used for
authentication.
They can store user-related state information and are sent between
the client and server.
2. GraphQL Subscriptions: