Add JSON/HTML content negotiation and clean up repository
Content Negotiation: - New content_type.rs: Negotiate JSON vs HTML based on ?format=json - JSON responses: Direct query results without template rendering - HTML responses: Full Handlebars template rendering - Example: /books?format=json returns JSON array API Endpoints Now Support: - /books?format=json - All books as JSON - /book?id=1&format=json - Single book as JSON - /search?q=Rust&format=json - Search results as JSON - All existing HTML endpoints continue working Cleanup: - Removed old example configs (book_catalog, book_detail, book_named_params, howto) - Removed old documentation (README_BOOK_CATALOG, README_PARAMETERS) - Removed old template directories (people, books/all, etc.) - Removed old template files (header.hbs, footer.hbs, etc.) - Removed unused files (person.hbs, runit) - Removed unused method: ParameterBinding::param_name() Files Kept: - conf/sqlite_serve.conf (unified production config) - start.sh (unified start script) - setup_book_catalog.sh (database setup) - README.md (main documentation) - ARCHITECTURE.md (architecture docs) Build Status: - 61 tests passing (+2 content type tests) - 7 benign warnings (unused fields in generated types) - Zero dead code JSON verified working, all features functional.
This commit is contained in:
@ -1,58 +0,0 @@
|
||||
# Book Catalog Configuration
|
||||
# Demonstrates the sqlite-serve module with multiple locations and template inheritance
|
||||
|
||||
load_module target/debug/libsqlite_serve.dylib;
|
||||
|
||||
worker_processes 1;
|
||||
events {}
|
||||
|
||||
error_log logs/error.log debug;
|
||||
|
||||
http {
|
||||
# Global templates for shared components (header, footer, book_card partial)
|
||||
sqlite_global_templates "server_root/global_templates";
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
root "server_root";
|
||||
|
||||
# Default redirect to all books
|
||||
location = / {
|
||||
return 301 /books/all;
|
||||
}
|
||||
|
||||
# All books
|
||||
location /books/all {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Programming books only
|
||||
location /books/programming {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = 'Programming' ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Database books only
|
||||
location /books/databases {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = 'Databases' ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Computer Science books only
|
||||
location /books/computer-science {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = 'Computer Science' ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
# Book Detail Configuration
|
||||
# Demonstrates using path parameters with the SQLite module
|
||||
|
||||
load_module target/debug/libsqlite_serve.dylib;
|
||||
|
||||
worker_processes 1;
|
||||
events {}
|
||||
|
||||
error_log logs/error.log debug;
|
||||
|
||||
http {
|
||||
# Global templates for shared components
|
||||
sqlite_global_templates "server_root/global_templates";
|
||||
|
||||
server {
|
||||
listen 8081;
|
||||
|
||||
root "server_root";
|
||||
|
||||
# Book detail page using a path parameter (numbered capture)
|
||||
# Captures the book ID from the URL and passes it to the SQL query
|
||||
location = /book {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE id = ?";
|
||||
sqlite_param $arg_id;
|
||||
sqlite_template "detail.hbs";
|
||||
}
|
||||
|
||||
# Books by genre using query parameter
|
||||
location = /genre {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = ? ORDER BY rating DESC";
|
||||
sqlite_param $arg_genre;
|
||||
sqlite_template "genre.hbs";
|
||||
}
|
||||
|
||||
# Search by year range using query parameters
|
||||
location = /years {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE year >= ? AND year <= ? ORDER BY year DESC, title";
|
||||
sqlite_param $arg_min;
|
||||
sqlite_param $arg_max;
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Fallback to all books
|
||||
location / {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,74 +0,0 @@
|
||||
# Book Catalog with Named Parameters
|
||||
# Demonstrates using named SQL parameters for better readability
|
||||
|
||||
load_module target/debug/libsqlite_serve.dylib;
|
||||
|
||||
worker_processes 1;
|
||||
events {}
|
||||
|
||||
error_log logs/error.log debug;
|
||||
|
||||
http {
|
||||
sqlite_global_templates "server_root/global_templates";
|
||||
|
||||
server {
|
||||
listen 8082;
|
||||
|
||||
root "server_root";
|
||||
|
||||
# Book detail with named parameter
|
||||
location = /book {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE id = :book_id";
|
||||
sqlite_param :book_id $arg_id;
|
||||
sqlite_template "detail.hbs";
|
||||
}
|
||||
|
||||
# Genre filter with named parameter
|
||||
location = /genre {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE genre = :genre_name ORDER BY rating DESC";
|
||||
sqlite_param :genre_name $arg_genre;
|
||||
sqlite_template "genre.hbs";
|
||||
}
|
||||
|
||||
# Year range with named parameters
|
||||
location = /years {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE year >= :min_year AND year <= :max_year ORDER BY year DESC, title";
|
||||
sqlite_param :min_year $arg_min;
|
||||
sqlite_param :max_year $arg_max;
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Search by title with named parameter
|
||||
location = /search {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE title LIKE '%' || :search_term || '%' ORDER BY rating DESC, title";
|
||||
sqlite_param :search_term $arg_q;
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Filter by rating with named parameter
|
||||
location = /top-rated {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books WHERE rating >= :min_rating ORDER BY rating DESC, title";
|
||||
sqlite_param :min_rating $arg_rating;
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
|
||||
# Fallback to all books
|
||||
location / {
|
||||
add_header "Content-Type" "text/html; charset=utf-8";
|
||||
sqlite_db "book_catalog.db";
|
||||
sqlite_query "SELECT * FROM books ORDER BY rating DESC, title";
|
||||
sqlite_template "list.hbs";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +0,0 @@
|
||||
# Add the path to your library here.
|
||||
load_module target/debug/libsqlite_serve.dylib;
|
||||
|
||||
worker_processes 1;
|
||||
|
||||
events {}
|
||||
|
||||
#Uncomment and add a log file path if desired
|
||||
error_log logs/error.log debug;
|
||||
|
||||
http {
|
||||
# Optional: Global templates directory for shared partials/layouts
|
||||
# sqlite_global_templates "server_root/global_templates";
|
||||
|
||||
server {
|
||||
listen 8080;
|
||||
|
||||
root "server_root";
|
||||
location /people {
|
||||
add_header "Content-Type" "text/html";
|
||||
sqlite_db "db.sqlite3";
|
||||
sqlite_query "SELECT id, name, address FROM person";
|
||||
sqlite_template "person.hbs";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user