PostgREST Workshop
Welcome to the comprehensive PostgREST and PostGIS workshop! This hands-on workshop will teach you how to build powerful REST APIs directly from your PostgreSQL database using PostgREST, with advanced spatial capabilities through PostGIS.
What You'll Learn
- PostgreSQL Fundamentals - Core database concepts and SQL operations
- PostGIS Spatial Extensions - Geographic data types and spatial operations
- PostgREST API Generation - Automatic REST API creation from database schema
- JWT Authentication - Secure API access with JSON Web Tokens
- Custom Functions - Implementing business logic with PostgreSQL functions
- Spatial APIs - Building location-aware applications with PostGIS and PostgREST
Prerequisites
- Basic understanding of databases and SQL
- Familiarity with REST APIs
- Docker installed on your system
- Basic command line knowledge
If you don't have Prerequisites full filled
Consider taking our course on Ultimate PostGIS training where we have covered everything from databases to deployments in 30 hours
Workshop Environment Setup
This workshop includes a complete Docker Compose setup with all required services. The docker-compose.yml file in this repository includes:
- PostgreSQL with PostGIS - Spatial database
- PostgREST - Automatic REST API generation
- pgAdmin - Database management interface
- Swagger UI - API documentation
- MkDocs - This documentation site
Database Initialization
The workshop includes pre-configured initialization scripts in the init-scripts/ directory:
01-init.sql- Creates database roles, tables, and sample data02-functions.sql- Creates PostgreSQL functions for the workshop
These scripts automatically set up: - PostgreSQL extensions (PostGIS, pgcrypto, pgjwt) - PostgREST authentication roles and permissions - Basic authentication functions (login, register) - Sample hello_world table for testing
Note: Most tables (workshops, participants, locations, regions, routes) are created as part of the documentation examples and should be run manually during the workshop.
Starting the Workshop Environment
-
Clone this repository:
-
Start all services:
-
Verify services are running:
Service Access Points
| Service | URL | Credentials |
|---|---|---|
| Workshop Documentation | http://localhost:8000 | N/A |
| PostgREST API | http://localhost:3000 | N/A |
| pgAdmin | http://localhost:8080 | admin@workshop.com / admin123 |
| Swagger UI | http://localhost:8081 | N/A |
| PostgreSQL | localhost:5432 | postgres / workshop123 |
pgAdmin Database Connection
When setting up pgAdmin:
- Open http://localhost:8080
- Login with admin@workshop.com / admin123
- Add new server with these settings:
- Name: Workshop Database
- Host: postgres
- Port: 5432
- Database: workshop
- Username: postgres
- Password: workshop123
Workshop Structure
Module 1: Introduction to PostgreSQL
Learn PostgreSQL fundamentals including data types, basic operations, and advanced features like JSON support and arrays.
Module 2: Introduction to PostGIS
Explore spatial data capabilities with PostGIS, including geometry types, spatial functions, and coordinate systems.
Module 3: Setting up PostgREST
Get PostgREST running and learn how to create REST APIs automatically from your database schema.
Module 4: Advanced Authentication
Implement secure authentication using JWT tokens and PostgreSQL's Row Level Security.
Module 5: Using Functions
Create custom PostgreSQL functions that become RPC endpoints in your PostgREST API.
Module 6: GIS with PostgREST
Combine PostgREST with PostGIS to build powerful spatial APIs for location-aware applications.
Quick Start Example
Once your environment is running, the database is pre-populated with sample data. Try these examples:
-
Test the basic API:
-
After creating tables in the workshop:
-
View API documentation:
- Open http://localhost:8081 for Swagger UI
- Open http://localhost:8000 for this workshop documentation
Troubleshooting
Common Issues
PostgREST not starting: - Check database connection in docker-compose logs - Verify database roles are created correctly
Permission denied errors: - Ensure proper GRANT statements are executed - Check that the correct role is being used
Spatial queries not working: - Verify PostGIS extension is installed - Check that spatial indexes are created
Useful Commands
# View logs for all services
docker-compose logs
# View logs for specific service
docker-compose logs postgres
docker-compose logs postgrest
docker-compose logs mkdocs
# Restart services
docker-compose restart
# Stop all services
docker-compose down
# Reset everything (removes data)
docker-compose down -v
# Rebuild and restart
docker-compose up -d --build
Resources
Workshop Support
If you encounter issues during the workshop:
- Check the troubleshooting section above
- Review the service logs using docker-compose logs
- Ensure all prerequisites are met
- Verify your Docker setup is working correctly
Let's begin with Introduction to PostgreSQL!