79:- module(simple_web,
80 [ run/0
81 , run/1
82 , read_json_dict/2
83 , read_json_dict/3
84 , reply_json_dict/1
85 , reply_json_dict/2
86 , reply_404/1
87 , reply_404/2
88 , reply_redirect/3
89 , url_for/2
90 ]
91). 92
93:- ( user:file_search_path(sw_app, _) ->
94 true
95 ;
96 working_directory(Dir, Dir),
97 asserta(user:file_search_path(sw_app, Dir))
98 ). 99
100:- use_module(sw_config_handling). 101
102:- reexport(sw). 103:- reexport(sw_static_handling). 104:- use_module(sw_route_handling). 105
106:- reexport(sw_template_handling). 107:- use_module(library(http/http_json),
108 [ http_read_json_dict/2 as read_json_dict
109 , http_read_json_dict/3 as read_json_dict
110 , reply_json_dict/1
111 , reply_json_dict/2
112 ]
113). 114:- use_module(library(http/http_dispatch),
115 [ http_404/2 as reply_404
116 , http_redirect/3 as reply_redirect
117 ]
118).
125reply_404(Request) :-
126 http_404([], Request).
127
128:- use_module(library(http/thread_httpd)). 129:- use_module(library(http/http_dispatch)). 130:- ( get_config(debug, true) ->
131 use_module(library(http/http_error))
132 ; true).
136run :-
137 sw_run([port(_)]), !.
143run(Options) :-
144 is_list(Options),
145 sw_run(Options), !.
146run(Options) :-
147 \+ is_list(Options),
148 sw_run([Options]), !.
152sw_run(Options) :-
153 init_routes,
154 http_server(http_dispatch, Options), !
Simple Web
Easy, simple websites with Prolog.
Example basic use
Create a directory with
app.pl
Inside this root directory, create a folder called
static
to save your static files, such as your css, javascript and images. Place an image calledlogo.jpg
into static/images/.Also inside the root directory, create a folder called
templates
, inside this placetest.html
Finally, run
app.pl
and navigate to http://localhost:5000More Examples
A repository of examples, including using static, templates and creating an API can be found in the simple_web_examples repository.