Advanced Programming of Web Applications

undefined
Server
N
S
W
I
1
5
3
 
-
 
A
d
v
a
n
c
e
d
 
P
r
o
g
r
a
m
m
i
n
g
 
o
f
 
W
e
b
 
A
p
p
l
i
c
a
t
i
o
n
s
 
2
0
2
3
/
2
0
2
4
P
e
t
r
 
Š
k
o
d
a
h
t
t
p
s
:
/
/
g
i
t
h
u
b
.
c
o
m
/
s
k
o
d
a
p
e
t
r
h
t
t
p
s
:
/
/
w
w
w
.
k
s
i
.
m
f
f
.
c
u
n
i
.
c
z
Starting point
PHP
$_GET, $_POST, $_REQUEST, $_SERVER
CGI / FastCGI / PHP-FPM / mod_php / mod_SuPHP / …
2
$app = AppFactory::create();
$app->setBasePath("/~skoda/lab-02");
$app->get('/name/{name}', function ($request, $response, $args) {
  $response->getBody()->write("Hello " . $args['name’]);
  return $response;
});
Demo
Python & Sockets
3
Web server
 
“A web server is computer software and
underlying hardware that accepts requests via
HTTP” 
Wikipedia 2024
 
Features:
Debug Mode / Error Handling / Logging
Routing
Static Files
Template Rendering
Request Data (POST, …) / Response Data
Sessions
SSL
 
4
<<actor>>
user
<<component>>
web server
 
Language:
PHP
Python
NodeJS
Java
 
Python
 
5
Python & Web framework
Flask is a Micro-Framework (no database, validator, … ).
6
app = Flask(__name__)
@app.route(
"/"
)
def
 hello_world():
    
return
 
"<p>Hello, World!</p>"
Demo
Python & 
Sockets
 Flask
7
<<actor>>
user
<<component>>
???
<<component>>
our code
Are we there yet?
Deployment:
uWSGI (Apache, Nginx, …)
mod_wsgi (Apache)
Gunicorn / …
CGI / FastCGI (Apache, Nginx, … )
Cloud
8
Python Web server
Gunicorn
WSGI and HTTP server for Unix
Pre-Fork Model
Sync Workers
Async Workers (coroutines)
Shared state/memory
9
app
 = Flask(__name__)
gunicorn -w 4 -b :8020 
wsgi:app
 
wsgi.py
JavaScript
NodeJS
Node.js
JavaScript runtime environment based on V8 engine.
Offers natively many code packages:
Net - socket API, supports both TCP and UDP
TLS – sockets with encryption
DNS, HTTP, HTTP/2
Accompanied by npm package management system.
Uses single-threaded main loop for async operations (like JS in browser).
In many cases offers both async and sync API calls.
Built-in N-API for C/C++ bindings (JS-C interoperability).
11
JavaScript & Web framework
Express
Fast, unopinionated, minimalist web framework for Node.js
Middleware (POST, XML, Metrics, ... )
12
const
 app = express();
app.get("/home/:name", (req, res) => { … });
app.listen(8080, () => { … });
Demo
NodeJS & Express
Middleware
Helmet
NodeJS Web server
Express
NODE_ENV="production“
node server.js
Process manager
Restart / OS Startup script
Clustering
Sticky sessions ?
Monitoring / Metrics
14
pm2 start npm --name my-app -i 4 -- start
PM2
NodeJS Alternatives
Deno
JavaScript, TypeScript, WebAssembly
All-in-one : linter, code formatter, …
By default, no I/O access for packages
Permissions list (network, env. variables, file
system)
Bun
Fast, Fast startup
All-in-one
15
Bun.js
 
16
Optional: 2023/2024
Deno
 
17
Optional: 2023/2024
Java
 
18
Java & Web framework
Why ?
JAX-RS
Specification only !
javax.ws.rs ~ jakarta.ws.rs (as of May 2019)
19
@Path("/pipeline")
public
 
class
 PipelineServlet {
    @GET
    @Path("/list")
    
public
 Response getPipelines(@Context HttpServletRequest request) { … }
}
Demo
Java & Jetty
 (Semi-)Improvised stand up ….
Application Server
“An application server is a 
software framework 
that provides both facilities to create web
applications and a server environment to run them.
...An application server acts as a set of components accessible to the software developer through a
standard 
API
 defined for the platform itself.
... they implement services like 
clustering
, 
failover
, and 
load-balancing
, … 
developers
 can 
focus
 on
implementing the 
business logic
.”  
Wikipedia 2023
21
History
Infoworld December 13, 1999
22
Java Server
It is Java ! ( Java Enterprise Edition )
Web Server vs Application Server
*.war
Servers:
Apache Tomcat / Apache TomEE
Jetty
WebLogic (Oracle)
WebSphere (IBM)
WildFly (Red Hat)
GlassFish
23
JAVA SE DEVELOPMENT KIT (JDK), VERSION 6
Licensed  Software is not designed or intended
for use in the design, construction, operation or
maintenance of any nuclear facility.
Java Embedded Server
Run server inside your application!
You are not alone .. (Spring Framework, ...)
24
Demo
Embedded Java Jetty
 (Semi-)Improvised stand up ….
Takeaway
Language specifics
General concepts
26
Slide Note
Embed
Share

This content covers advanced programming topics related to web applications, including PHP, Python, web servers, frameworks like Flask, and deployment strategies like uWSGI and Gunicorn. It discusses key concepts such as server management, handling requests, routing, SSL, and more.

  • Web Development
  • Programming
  • PHP
  • Python
  • Flask

Uploaded on Sep 30, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Server NSWI153 NSWI153 - - Advanced Advanced Programming of Web Applications Programming of Web Applications 202 2023/2024 3/2024 Petr Petr koda koda https://github.com/skodapetr https://github.com/skodapetr https://www.ksi.mff.cuni.cz https://www.ksi.mff.cuni.cz Creative Commons Attribution 4.0 International License This work is licensed under a Creative Commons Attribution 4.0 International License.

  2. Starting point PHP $_GET, $_POST, $_REQUEST, $_SERVER CGI / FastCGI / PHP-FPM / mod_php / mod_SuPHP / $app = AppFactory::create(); $app->setBasePath("/~skoda/lab-02"); $app->get('/name/{name}', function ($request, $response, $args) { $response->getBody()->write("Hello " . $args['name ]); return $response; }); 2

  3. Demo Python & Sockets 3

  4. Web server A web server is computer software and underlying hardware that accepts requests via HTTP Wikipedia 2024 Features: Debug Mode / Error Handling / Logging Routing Language: Static Files PHP Template Rendering Python Request Data (POST, ) / Response Data NodeJS Sessions Java SSL <<actor>> user <<component>> web server 4

  5. 5 Python

  6. Python & Web framework Flask is a Micro-Framework (no database, validator, ). Slim Framework $app = AppFactory::create(); app = Flask(__name__) $app->get('/name/{name} , .); @app.route("/") def hello_world(): return "<p>Hello, World!</p>" 6

  7. Demo Python & Sockets Flask <<actor>> user <<component>> ??? <<component>> our code 7

  8. Are we there yet? Deployment: uWSGI (Apache, Nginx, ) mod_wsgi (Apache) Gunicorn / CGI / FastCGI (Apache, Nginx, ) Cloud 8

  9. Python Web server Gunicorn WSGI and HTTP server for Unix Pre-Fork Model Sync Workers Async Workers (coroutines) wsgi.py Shared state/memory app = Flask(__name__) gunicorn -w 4 -b :8020 wsgi:app 9

  10. JavaScript NodeJS

  11. Node.js JavaScript runtime environment based on V8 engine. Offers natively many code packages: Net - socket API, supports both TCP and UDP TLS sockets with encryption DNS, HTTP, HTTP/2 Accompanied by npm package management system. Uses single-threaded main loop for async operations (like JS in browser). In many cases offers both async and sync API calls. Built-in N-API for C/C++ bindings (JS-C interoperability). 11

  12. JavaScript & Web framework Express Slim Framework Fast, unopinionated, minimalist web framework for Node.js Middleware (POST, XML, Metrics, ... ) $app = AppFactory::create(); $app->get('/name/{name} , .); Flask const app = express(); app = Flask(__name__) app.get("/home/:name", (req, res) => { }); @app.route("/") def hello_world(): return "<p>Hello, World!</p>" app.listen(8080, () => { }); 12

  13. Demo NodeJS & Express Middleware Helmet

  14. NodeJS Web server Express PM2 NODE_ENV="production pm2 start npm --name my-app -i 4 -- start node server.js Process manager Restart / OS Startup script Clustering Sticky sessions ? Monitoring / Metrics 14

  15. NodeJS Alternatives Deno Bun JavaScript, TypeScript, WebAssembly Fast, Fast startup All-in-one : linter, code formatter, All-in-one By default, no I/O access for packages Permissions list (network, env. variables, file system) 15

  16. Java 18

  17. Java & Web framework Why ? JAX-RS Specification only ! javax.ws.rs ~ jakarta.ws.rs (as of May 2019) @Path("/pipeline") public class PipelineServlet { @GET @Path("/list") public Response getPipelines(@Context HttpServletRequest request) { } } 19

  18. Demo Java & Jetty (Semi-)Improvised stand up .

  19. Application Server An application server is a software framework that provides both facilities to create web applications and a server environment to run them. ...An application server acts as a set of components accessible to the software developer through a standard API defined for the platform itself. ... they implement services like clustering, failover, and load-balancing, developers can focus on implementing the business logic. Wikipedia 2023 21

  20. History Infoworld December 13, 1999 22

  21. Java Server It is Java ! ( Java Enterprise Edition ) Web Server Application Server Web Server vs Application Server Servlets Servlets JSP JSP *.war WebSockets WebSockets Servers: JTA JTA Apache Tomcat / Apache TomEE JASPIC Bean Validation EJB Jetty JAVA SE DEVELOPMENT KIT (JDK), VERSION 6 Licensed Software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility. JPA WebLogic (Oracle) JMS WebSphere (IBM) JavaMail JAX-RS WildFly (Red Hat) JAX-WS GlassFish 23

  22. Java Embedded Server Run server inside your application! You are not alone .. (Spring Framework, ...) 24

  23. Demo Embedded Java Jetty (Semi-)Improvised stand up .

  24. Takeaway Language specifics General concepts 26

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#