A Go REST API for scraping and fetching my Letterboxd favorites, storing the data to MongoDB. JWT token is generated using a secret word and username flag.
# Initialize Go module
go mod init boxd
# Install dependencies
go mod tidy
- Go 1.16 or later
- MongoDB instance
Letterboxd username and monogdb can be set via a flag when starting the server.
LETTERBOXD_USERNAME
: Letterboxd usernameMONGODB_URI
: MongoDB connection string (required for POST endpoint)JWT_SECRET
: jwt token used to authenticate requests againstAUTH_SECRET_WORD
: for validating a jwt token generation.PORT
: Server port (defaults to 8080)
-username
: Override the Letterboxd username-mongodb-uri
: Override the MongoDB connection URI
Start the server:
export LETTERBOXD_USERNAME=yourusername
export MONGODB_URI=mongodb://localhost:27017
go run main.go
Returns a JSON array of Letterboxd favorite movies.
Example response:
[
{
"title": "The Godfather",
"year": "1972",
"imageUrl": "https://letterboxd.com/path/to/image.jpg",
"movieUrl": "https://letterboxd.com/film/the-godfather/",
"updatedAt": "2024-03-21T15:04:05Z"
}
]
Scrapes Letterboxd favorites and saves them to MongoDB.
Example response:
{
"message": "Successfully saved favorites to database",
"count": "4"
}
Both endpoints have CORS enabled, allowing requests from any origin.
All endpoints (except the health check endpoint /) require authentication using a Bearer token.
Include the token in the Authorization header for all requests. Example Requests:
# Get favorites
curl -X GET http://localhost:8080/favourites \
-H "Authorization: Bearer your_token_here"
# Scrape and save favorites
curl -X POST http://localhost:8080/favourites \
-H "Authorization: Bearer your_token_here"
Error Responses
Missing token:
{
"error": "Authorization header required"
}
Invalid token:
{
"error": "Invalid token"
}