SlideShare una empresa de Scribd logo
1 de 17
Priyanka Wadhwa
Knoldus Software LLP
Priyanka Wadhwa
Knoldus Software LLP
Web Application using Clojure
Leiningen- a building tool...
● Clojure requires the Java Virtual Machine (JVM) to run
● Clojure applications can be built with the standard Java tools, such as Maven, Ant or
Leiningen.
● Leiningen is a one-stop shop for all your project-management-related needs.
● Leiningen is compatible with Maven, so it has access to large and well-maintained
repositories of Java libraries.
● Clojure libraries are commonly found in the Clojures repository. This repository is, enabled
by default in Leiningen.
Installation...
1. Download the Lein script-
https://raw.github.com/technomancy/leiningen/stable/bin/lein
2.Place it on your $PATH where your shell can find it- mv lein ~/bin
3.Set it to be executable- chmod +x lein
4.Run it (lein) and it will download the self-install package – lein self-install
5.lein new luminus example
cd example
lein ring server
//for h2 supported database
lein new luminus example +h2
cd example
(will contain project.clj file with declaration of the project (including dependencies on
Clojure), the README file with template of project's description, and two directories — src
and test for source code & tests. Now you can start to work with you project.)
Light Table(Clojure IDE)...
“the next generation code editor”
download Link- http://www.lighttable.com/.(and upload your project)
Template Tree Structure....Procfile
README.md
project.clj -used for configuring and building the application
src
└ log4j.xml
guestbook
└ handler.clj -handler that’s going to handle all the requests to it.
util.clj -
repl.clj
models -The models namespace is used to define the model for the application and handle the persistence layer.
└ db.clj -used to house the functions for interacting with the database
schema.clj -used to define the connection parameters and the database tables
routes -The routes namespace is where the routes and controllers for our homepage are located
└ home.clj
views -The views namespace defines the visual layout of the application.
└ layout.clj
└ templates
└ about.html
base.html
home.html
test
└ guestbook
└ test
└ handler.clj
resources -we put all the static resoruces for our application.
└ public
└ css
└ bootstrap-theme.min.css
bootstrap.min.css
screen.css
fonts
└ glyphicons-halflings-regular.eot
glyphicons-halflings-regular.svg
glyphicons-halflings-regular.ttf
glyphicons-halflings-regular.woff
img
js
└ bootstrap.min.css
md
└ docs.md
Luminus API...
● Selmer - HTML Templating
● Hiccup – HTML Templating
● Compojure – Accessing Database
● Ring – Accessing Database
● lib Noir – Validation, Session handling, etc.
● SQL Korma – Tasty SQL for Clojure
Selmer compiles the template files and replaces any tags with the corresponding functions for handling dynamic content.
Selmer separates the presentation logic from the program logic.
Step1: HTML templating using selmer- (handling dynamic content)
<html>
<head>
<title>My First Template</title>
</head>
<body>
<h2>Hello {{name}}</h2>
<h2>E-mail {{e-mail}}</h2>
</body>
</html>
The templates are rendered using a context represented by a map of key/value pairs. {{name}}- variables that we render during the run time.
Step2: Renderig the above variable at runtime using render-file
(ns example.routes.home
(:use [selmer.parser :only [render-file]]))
(defn index [request]
(render-file "example/views/templates/index.html"
{:name "John" :e-mail ”testing@example.com”}))
pass in a collection we can iterate it using the for tag:
<ul>
{% for item in items %}
<li> {{item}} </li>
{% endfor %}
</ul>
(render-file "/example/views/templates/items.html
{:items (range 10)})
Selmer...
Selmer Template inheritance...
The extends tag or the include tag:
Extending Template-
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
</body>
Including Template-
<body>
<div id="content">
{% if user %}
{% include "templates/home.html" %}
{% else %}
{% include "templates/login.html" %}
{% endif %}
</div>
Hiccup...
Hiccup is a popular HTML templating engine for Clojure. The advantage of using Hiccup
is that it uses Clojure to generate and manipulate our markup. This means that you don't
have to learn a separate DSL for generating your HTML with its own rules.
In Hiccup, HTML elements are represented by Clojure vectors:
Syntax: [:tag-name {:attribute-key "attribute value"} tag-body]
Example:
[:div {:id "test", :class "example"} [:p "Hello world!"]]
which corresponds to the following HTML:
<div id="text" class="example"><p>Hello world!</p></div>
Also, the same can be coded as-
[:div#test.example [:p "Hello world!"]]
HTML Templating with Hiccup...
Hiccup helpers for creating HTML forms for our Web Application-
(form-to [:post "/login"]
(text-field {:placeholder "name"} "id")
(password-field {:placeholder "password"} "pass")
(submit-button "login"))
Is Equivalent to:
<form action="/login" method="POST">
<input id="id" name="id" placeholder="name" type="text" />
<input id="pass" name="pass" placeholder="password" type="password" />
<input type="submit" value="login" />
</form>
Ring & Compojure...
● Compojure is the library that maps URLs to functions in our program(define application routes).
● Compojure provides a defroute macro which can group several routes together and bind them to a symbol-
(defroutes auth-routes
(POST "/login" [id pass] (login id pass))
(POST "/logout" [] (logout)))
or, It is also possible to group routes by common path elements using context
(def home-routes
(context "/user/:id" [id]
(GET "/profile" [] ...)
(GET "/settings" [] ...)
(GET "/change-password" [] ...)))
* After defining the routes, they are added to the routes vector in handler file.
Ring & Compojure...(continued)
Ring is a basic web framework. We can compare it to Servlets in JavaEE. It provides
basic functionality for handling requests, but isn't very high level or full of features. In
particular, it requires to write routes.
Ring is low level API for web application development. For example, it uses maps data
structures to wrap request and response.
Compojure provides an elegant routing library. Most of time, it is used with Ring.
Ring is a basic web framework. We can compare it to Servlets in JavaEE. It provides
basic functionality for handling requests, but isn't very high level or full of features. In
particular, it requires to write routes.
Ring is low level API for web application development. For example, it uses maps data
structures to wrap request and response.
Compojure provides an elegant routing library. Most of time, it is used with Ring.
Restricted Access...(uses noir library)
//Making Routes Restricted:
(defroutes private-pages
(GET "/profile" [ ] (restricted (show-profile)))
(GET "/secret-page1" [ ] (restricted (show-secret-page)))
(GET "/secret-page2" [ ] (restricted (another-secret-page))))
noir.util.route/restricted macro is used to indicated that access rules apply to the
route.
For marking multiple routes as restricted we use:
(def-restricted-routes private-pages())
//Making Routes Restricted:
(defroutes private-pages
(GET "/profile" [ ] (restricted (show-profile)))
(GET "/secret-page1" [ ] (restricted (show-secret-page)))
(GET "/secret-page2" [ ] (restricted (another-secret-page))))
noir.util.route/restricted macro is used to indicated that access rules apply to the
route.
For marking multiple routes as restricted we use:
(def-restricted-routes private-pages())
Adding the Data Models...
Step3: All the dependencies for mentioned API's are managed via updating the project.clj file:
:dependencies
[[ring-server "0.3.1"]
[com.h2database/h2 "1.3.175"]
[korma "0.3.0-RC6"]
[org.clojure/clojure "1.6.0"]
[selmer "0.6.5"]
[lib-noir "0.8.1"]
[compojure "1.1.6"]]
:plugins [[lein-ring "0.8.10"] [lein-environ "0.4.0"]]
Step4: creating a database model in schema.clj file: (defination in the form of map)
(def db-spec {:classname "org.h2.Driver"
:subprotocol "h2"
:subname (str (io/resource-path) db-store)
:user "sa"
:password ""
:naming {:keys clojure.string/upper-case
:fields clojure.string/upper-case}})
Next, to write a function creating the database table schema.
(defn create-users-table [ ]
(sql/with-connection db-spec
(sql/create-table
:users[
:id “varchar(5)”
:e-mail “varchar(30)”])))
now, a calling function for table:
(defn create-table [ ]
(create-users-table))
Step5: creating routes for the html pages using above described compojures and also the associated
functions having the validations/functionalities.
References...
● http://www.luminusweb.net
Thank You...

Más contenido relacionado

La actualidad más candente

Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScripttmont
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On RandomnessRanel Padon
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript ObjectsReem Alattas
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekyoavrubin
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshuSidd Singh
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScriptJoseph Smith
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data scienceJohn Cant
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: NotesRoberto Casadei
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScriptWebF
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about lazinessJohan Tibell
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Philip Schwarz
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 
Templates presentation
Templates presentationTemplates presentation
Templates presentationmalaybpramanik
 

La actualidad más candente (20)

Introduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScriptIntroduction to Functional Programming in JavaScript
Introduction to Functional Programming in JavaScript
 
Python Programming - IX. On Randomness
Python Programming - IX. On RandomnessPython Programming - IX. On Randomness
Python Programming - IX. On Randomness
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
Functional programming in JavaScript
Functional programming in JavaScriptFunctional programming in JavaScript
Functional programming in JavaScript
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Haskell for data science
Haskell for data scienceHaskell for data science
Haskell for data science
 
Functional Programming in Scala: Notes
Functional Programming in Scala: NotesFunctional Programming in Scala: Notes
Functional Programming in Scala: Notes
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Reasoning about laziness
Reasoning about lazinessReasoning about laziness
Reasoning about laziness
 
Joy of scala
Joy of scalaJoy of scala
Joy of scala
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Why Haskell
Why HaskellWhy Haskell
Why Haskell
 
Algorithm and Programming (Array)
Algorithm and Programming (Array)Algorithm and Programming (Array)
Algorithm and Programming (Array)
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 

Similar a Knolx session

Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introductionCommit University
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaAgile Testing Alliance
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application developmentzonathen
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるSadaaki HIRAI
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesShabir Ahmad
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuAppUniverz Org
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on RailsViridians
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Racksickill
 
Next Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooNext Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooStefan Schmidt
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)Daniel Bryant
 

Similar a Knolx session (20)

sveltekit-en.pdf
sveltekit-en.pdfsveltekit-en.pdf
sveltekit-en.pdf
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
 
NodeJS
NodeJSNodeJS
NodeJS
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Week 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. WuWeek 05 Web, App and Javascript_Brandon, S.H. Wu
Week 05 Web, App and Javascript_Brandon, S.H. Wu
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Intro to Sails.js
Intro to Sails.jsIntro to Sails.js
Intro to Sails.js
 
Next Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring RooNext Generation Spring MVC with Spring Roo
Next Generation Spring MVC with Spring Roo
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 

Más de Knoldus Inc.

Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxKnoldus Inc.
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxKnoldus Inc.
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxKnoldus Inc.
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxKnoldus Inc.
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationKnoldus Inc.
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationKnoldus Inc.
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIsKnoldus Inc.
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II PresentationKnoldus Inc.
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAKnoldus Inc.
 
Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Knoldus Inc.
 
Azure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptxAzure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptxKnoldus Inc.
 
The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinThe Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinKnoldus Inc.
 
Data Engineering with Databricks Presentation
Data Engineering with Databricks PresentationData Engineering with Databricks Presentation
Data Engineering with Databricks PresentationKnoldus Inc.
 
Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)Knoldus Inc.
 
NoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptxNoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptxKnoldus Inc.
 
Mastering Distributed Performance Testing
Mastering Distributed Performance TestingMastering Distributed Performance Testing
Mastering Distributed Performance TestingKnoldus Inc.
 
MLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptxMLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptxKnoldus Inc.
 
Introduction to Ansible Tower Presentation
Introduction to Ansible Tower PresentationIntroduction to Ansible Tower Presentation
Introduction to Ansible Tower PresentationKnoldus Inc.
 
CQRS with dot net services presentation.
CQRS with dot net services presentation.CQRS with dot net services presentation.
CQRS with dot net services presentation.Knoldus Inc.
 

Más de Knoldus Inc. (20)

Robusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptxRobusta -Tool Presentation (DevOps).pptx
Robusta -Tool Presentation (DevOps).pptx
 
Optimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptxOptimizing Kubernetes using GOLDILOCKS.pptx
Optimizing Kubernetes using GOLDILOCKS.pptx
 
Azure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptxAzure Function App Exception Handling.pptx
Azure Function App Exception Handling.pptx
 
CQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptxCQRS Design Pattern Presentation (Java).pptx
CQRS Design Pattern Presentation (Java).pptx
 
ETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake PresentationETL Observability: Azure to Snowflake Presentation
ETL Observability: Azure to Snowflake Presentation
 
Scripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics PresentationScripting with K6 - Beyond the Basics Presentation
Scripting with K6 - Beyond the Basics Presentation
 
Getting started with dotnet core Web APIs
Getting started with dotnet core Web APIsGetting started with dotnet core Web APIs
Getting started with dotnet core Web APIs
 
Introduction To Rust part II Presentation
Introduction To Rust part II PresentationIntroduction To Rust part II Presentation
Introduction To Rust part II Presentation
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Configuring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRAConfiguring Workflows & Validators in JIRA
Configuring Workflows & Validators in JIRA
 
Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)Advanced Python (with dependency injection and hydra configuration packages)
Advanced Python (with dependency injection and hydra configuration packages)
 
Azure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptxAzure Databricks (For Data Analytics).pptx
Azure Databricks (For Data Analytics).pptx
 
The Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and KotlinThe Power of Dependency Injection with Dagger 2 and Kotlin
The Power of Dependency Injection with Dagger 2 and Kotlin
 
Data Engineering with Databricks Presentation
Data Engineering with Databricks PresentationData Engineering with Databricks Presentation
Data Engineering with Databricks Presentation
 
Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)Databricks for MLOps Presentation (AI/ML)
Databricks for MLOps Presentation (AI/ML)
 
NoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptxNoOps - (Automate Ops) Presentation.pptx
NoOps - (Automate Ops) Presentation.pptx
 
Mastering Distributed Performance Testing
Mastering Distributed Performance TestingMastering Distributed Performance Testing
Mastering Distributed Performance Testing
 
MLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptxMLops on Vertex AI Presentation (AI/ML).pptx
MLops on Vertex AI Presentation (AI/ML).pptx
 
Introduction to Ansible Tower Presentation
Introduction to Ansible Tower PresentationIntroduction to Ansible Tower Presentation
Introduction to Ansible Tower Presentation
 
CQRS with dot net services presentation.
CQRS with dot net services presentation.CQRS with dot net services presentation.
CQRS with dot net services presentation.
 

Último

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Último (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Knolx session

  • 1. Priyanka Wadhwa Knoldus Software LLP Priyanka Wadhwa Knoldus Software LLP Web Application using Clojure
  • 2. Leiningen- a building tool... ● Clojure requires the Java Virtual Machine (JVM) to run ● Clojure applications can be built with the standard Java tools, such as Maven, Ant or Leiningen. ● Leiningen is a one-stop shop for all your project-management-related needs. ● Leiningen is compatible with Maven, so it has access to large and well-maintained repositories of Java libraries. ● Clojure libraries are commonly found in the Clojures repository. This repository is, enabled by default in Leiningen.
  • 3. Installation... 1. Download the Lein script- https://raw.github.com/technomancy/leiningen/stable/bin/lein 2.Place it on your $PATH where your shell can find it- mv lein ~/bin 3.Set it to be executable- chmod +x lein 4.Run it (lein) and it will download the self-install package – lein self-install 5.lein new luminus example cd example lein ring server //for h2 supported database lein new luminus example +h2 cd example (will contain project.clj file with declaration of the project (including dependencies on Clojure), the README file with template of project's description, and two directories — src and test for source code & tests. Now you can start to work with you project.)
  • 4. Light Table(Clojure IDE)... “the next generation code editor” download Link- http://www.lighttable.com/.(and upload your project)
  • 5. Template Tree Structure....Procfile README.md project.clj -used for configuring and building the application src └ log4j.xml guestbook └ handler.clj -handler that’s going to handle all the requests to it. util.clj - repl.clj models -The models namespace is used to define the model for the application and handle the persistence layer. └ db.clj -used to house the functions for interacting with the database schema.clj -used to define the connection parameters and the database tables routes -The routes namespace is where the routes and controllers for our homepage are located └ home.clj views -The views namespace defines the visual layout of the application. └ layout.clj └ templates └ about.html base.html home.html test └ guestbook └ test └ handler.clj resources -we put all the static resoruces for our application. └ public └ css └ bootstrap-theme.min.css bootstrap.min.css screen.css fonts └ glyphicons-halflings-regular.eot glyphicons-halflings-regular.svg glyphicons-halflings-regular.ttf glyphicons-halflings-regular.woff img js └ bootstrap.min.css md └ docs.md
  • 6. Luminus API... ● Selmer - HTML Templating ● Hiccup – HTML Templating ● Compojure – Accessing Database ● Ring – Accessing Database ● lib Noir – Validation, Session handling, etc. ● SQL Korma – Tasty SQL for Clojure
  • 7. Selmer compiles the template files and replaces any tags with the corresponding functions for handling dynamic content. Selmer separates the presentation logic from the program logic. Step1: HTML templating using selmer- (handling dynamic content) <html> <head> <title>My First Template</title> </head> <body> <h2>Hello {{name}}</h2> <h2>E-mail {{e-mail}}</h2> </body> </html> The templates are rendered using a context represented by a map of key/value pairs. {{name}}- variables that we render during the run time. Step2: Renderig the above variable at runtime using render-file (ns example.routes.home (:use [selmer.parser :only [render-file]])) (defn index [request] (render-file "example/views/templates/index.html" {:name "John" :e-mail ”testing@example.com”})) pass in a collection we can iterate it using the for tag: <ul> {% for item in items %} <li> {{item}} </li> {% endfor %} </ul> (render-file "/example/views/templates/items.html {:items (range 10)}) Selmer...
  • 8. Selmer Template inheritance... The extends tag or the include tag: Extending Template- <body> <div id="content"> {% block content %}{% endblock %} </div> </body> Including Template- <body> <div id="content"> {% if user %} {% include "templates/home.html" %} {% else %} {% include "templates/login.html" %} {% endif %} </div>
  • 9. Hiccup... Hiccup is a popular HTML templating engine for Clojure. The advantage of using Hiccup is that it uses Clojure to generate and manipulate our markup. This means that you don't have to learn a separate DSL for generating your HTML with its own rules. In Hiccup, HTML elements are represented by Clojure vectors: Syntax: [:tag-name {:attribute-key "attribute value"} tag-body] Example: [:div {:id "test", :class "example"} [:p "Hello world!"]] which corresponds to the following HTML: <div id="text" class="example"><p>Hello world!</p></div> Also, the same can be coded as- [:div#test.example [:p "Hello world!"]]
  • 10. HTML Templating with Hiccup... Hiccup helpers for creating HTML forms for our Web Application- (form-to [:post "/login"] (text-field {:placeholder "name"} "id") (password-field {:placeholder "password"} "pass") (submit-button "login")) Is Equivalent to: <form action="/login" method="POST"> <input id="id" name="id" placeholder="name" type="text" /> <input id="pass" name="pass" placeholder="password" type="password" /> <input type="submit" value="login" /> </form>
  • 11. Ring & Compojure... ● Compojure is the library that maps URLs to functions in our program(define application routes). ● Compojure provides a defroute macro which can group several routes together and bind them to a symbol- (defroutes auth-routes (POST "/login" [id pass] (login id pass)) (POST "/logout" [] (logout))) or, It is also possible to group routes by common path elements using context (def home-routes (context "/user/:id" [id] (GET "/profile" [] ...) (GET "/settings" [] ...) (GET "/change-password" [] ...))) * After defining the routes, they are added to the routes vector in handler file.
  • 12. Ring & Compojure...(continued) Ring is a basic web framework. We can compare it to Servlets in JavaEE. It provides basic functionality for handling requests, but isn't very high level or full of features. In particular, it requires to write routes. Ring is low level API for web application development. For example, it uses maps data structures to wrap request and response. Compojure provides an elegant routing library. Most of time, it is used with Ring. Ring is a basic web framework. We can compare it to Servlets in JavaEE. It provides basic functionality for handling requests, but isn't very high level or full of features. In particular, it requires to write routes. Ring is low level API for web application development. For example, it uses maps data structures to wrap request and response. Compojure provides an elegant routing library. Most of time, it is used with Ring.
  • 13. Restricted Access...(uses noir library) //Making Routes Restricted: (defroutes private-pages (GET "/profile" [ ] (restricted (show-profile))) (GET "/secret-page1" [ ] (restricted (show-secret-page))) (GET "/secret-page2" [ ] (restricted (another-secret-page)))) noir.util.route/restricted macro is used to indicated that access rules apply to the route. For marking multiple routes as restricted we use: (def-restricted-routes private-pages()) //Making Routes Restricted: (defroutes private-pages (GET "/profile" [ ] (restricted (show-profile))) (GET "/secret-page1" [ ] (restricted (show-secret-page))) (GET "/secret-page2" [ ] (restricted (another-secret-page)))) noir.util.route/restricted macro is used to indicated that access rules apply to the route. For marking multiple routes as restricted we use: (def-restricted-routes private-pages())
  • 14. Adding the Data Models... Step3: All the dependencies for mentioned API's are managed via updating the project.clj file: :dependencies [[ring-server "0.3.1"] [com.h2database/h2 "1.3.175"] [korma "0.3.0-RC6"] [org.clojure/clojure "1.6.0"] [selmer "0.6.5"] [lib-noir "0.8.1"] [compojure "1.1.6"]] :plugins [[lein-ring "0.8.10"] [lein-environ "0.4.0"]] Step4: creating a database model in schema.clj file: (defination in the form of map) (def db-spec {:classname "org.h2.Driver" :subprotocol "h2" :subname (str (io/resource-path) db-store) :user "sa" :password "" :naming {:keys clojure.string/upper-case :fields clojure.string/upper-case}})
  • 15. Next, to write a function creating the database table schema. (defn create-users-table [ ] (sql/with-connection db-spec (sql/create-table :users[ :id “varchar(5)” :e-mail “varchar(30)”]))) now, a calling function for table: (defn create-table [ ] (create-users-table)) Step5: creating routes for the html pages using above described compojures and also the associated functions having the validations/functionalities.