(1) Route :-
we will talk about :-
  • What is the Route Way ?
  • What is the Route.ring file ?
  • How to use Route.ring file and route function ?
  • Hello World Application .

What is the Route Ways ?

The route way is a method to route your project urls ,so can the user access to it easily and secure.


What is the Route.ring file

The Route.ring file is the main file in the project , It is like the heart of the body .


How to use Route.ring file

First of all be sure the first line is:-

  • In Windows :- [ #!ring -cgi ]
  • In Linux OS :- [ #!/usr/bin/ring -cgi ]
  • In Mac OS :- [#!/usr/local/bin/ring -cgi]

Why ? :- The web application will not work on the browser if there is no line like that...
The Second thing make sure to load this file and import the web packages :-
load 'dragon-ring.ring'
import system.Web

Third step is the strat working with Dragon-Ring by route function :-
#!ring -cgi 
load 'dragon-ring.ring'
import system.Web
app.route('index',:htmlstr,"<h1>The Index Page</h1>")

the route function used from app class and it takes three parameters ,So app.route(CUrl,Croutetype,Ccode)
  • Curl the page url (It takes one page like 'index' , 'about' , 'login'; Or a list like routing "localhost/index/hello" ['index','hello'] ).
  • Ctype the type of the page , the types is :-
    • (:htmlstr) execute html code from strings.
    • (:ringfunc) execute html code from ring functions.
    • (:ringfile) execute html code from ring file as a (Controller),[it reads the ring file from 'website' folder]
    • (:htmlfile) execute html code from html files (not templates).
  • Ccode is the code is going to execute depends on Ctype .


Hello World Application

Now we will learn how to create Hello World app in a different methods:-
(1) First Way :-

#!ring -cgi 
load 'dragon-ring.ring'
import system.Web
app.route('helloworld',:htmlstr,"<h1>Hello World</h1>")

(2) Second way :-
#!ring -cgi 
load 'dragon-ring.ring'
import system.Web
app.route('HelloWorld',:ringfunc,"hello()")
func hello()
     return html('Hello World')

according to html() function it has defined in Page class in "Weblib.ring" but this function can be used as any other function (because it will add the html code inside the object).
(3) Third way :-
#!ring -cgi 
load 'dragon-ring.ring'
import system.Web
app.route('HelloWorld',:ringfile,"hello.ring")

In the website/hello.ring File we have this code
 html('Hello World')

also we can use Object :-
import system.Web
dring{ 
      h1('Hello World')  /* or */ html('<h1>Hello World</h1>')
     }

you Don`t have to import System.Web in any .ring file you want to use it as a controller.


For advanced code and experience developers

You can create your class and use it . in the website/hello.ring we have this code and in the route.ring we have the same code in the first way ...

import system.Web

new hello{start()}

class hello
     func start
          dring{ 
               h1('Hello World')  /* or */ html('<h1>Hello World</h1>')
         }

I hope it was easy for you ...