A simple RESTful API built with Sinatra for validating ISBN-10 and ISBN-13 strings and retrieving the version of the isbn_field gem.
- Clone the repository
- Install dependencies:
bundle install
- Run the application:
rackup -p 4567 config.ru
Endpoint: POST /validate
Request Body:
{
"isbn": "978-0-596-52068-7"
}
Response:
- For valid ISBN:
{ "valid": true, "message": "validation pass" }
- For invalid ISBN:
{ "valid": false, "message": "validation failed" }
- For incorrect format:
{ "valid": false, "message": "wrong format" }
- If ISBN is not provided:
{ "valid": false, "message": "ISBN is required" }
Endpoint: GET /version
Response:
{
"version": "0.1.2"
}
Using curl:
# Validate ISBN-10
curl -X POST http://localhost:4567/validate \
-H "Content-Type: application/json" \
-d '{"isbn": "0321765723"}'
# Validate ISBN-13
curl -X POST http://localhost:4567/validate \
-H "Content-Type: application/json" \
-d '{"isbn": "978-0321765723"}'
# Get version
curl -X GET http://localhost:4567/version