SlideShare ist ein Scribd-Unternehmen logo
1 von 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...

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Knoldus Inc.

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxKnoldus Inc.
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingKnoldus Inc.
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionKnoldus Inc.
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxKnoldus Inc.
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptxKnoldus Inc.
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfKnoldus Inc.
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxKnoldus Inc.
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingKnoldus Inc.
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesKnoldus Inc.
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxKnoldus 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.
 

Mehr von Knoldus Inc. (20)

Supply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptxSupply chain security with Kubeclarity.pptx
Supply chain security with Kubeclarity.pptx
 
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML ParsingMastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
Mastering Web Scraping with JSoup Unlocking the Secrets of HTML Parsing
 
Akka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On IntroductionAkka gRPC Essentials A Hands-On Introduction
Akka gRPC Essentials A Hands-On Introduction
 
Entity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptxEntity Core with Core Microservices.pptx
Entity Core with Core Microservices.pptx
 
Introduction to Redis and its features.pptx
Introduction to Redis and its features.pptxIntroduction to Redis and its features.pptx
Introduction to Redis and its features.pptx
 
GraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdfGraphQL with .NET Core Microservices.pdf
GraphQL with .NET Core Microservices.pdf
 
NuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptxNuGet Packages Presentation (DoT NeT).pptx
NuGet Packages Presentation (DoT NeT).pptx
 
Data Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable TestingData Quality in Test Automation Navigating the Path to Reliable Testing
Data Quality in Test Automation Navigating the Path to Reliable Testing
 
K8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose KubernetesK8sGPTThe AI​ way to diagnose Kubernetes
K8sGPTThe AI​ way to diagnose Kubernetes
 
Introduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptxIntroduction to Circle Ci Presentation.pptx
Introduction to Circle Ci Presentation.pptx
 
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
 

Kürzlich hochgeladen

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

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.