copyleftdev/phonecheck
High-performance phone number validation REST API built with Zig and Google's libphonenumber. Fast, safe, and production-ready alternative to commerci...
A high-performance, production-ready REST API for phone number validation built with Zig and wrapping Google's libphonenumber C++ library.
๐ Free alternative to Twilio Lookup - Validate 10M numbers/month for $40 instead of $50,000
โก 2,500+ req/s throughput - Battle-tested with simulated annealing load analysis
๐ Memory-safe - Zig's compile-time guarantees + arena allocators
You need to install Google's libphonenumber C++ library:
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install -y \
libphonenumber-dev \
libprotobuf-dev \
libicu-dev \
cmake \
build-essential
macOS (Homebrew):
brew install libphonenumber protobuf icu4c
Arch Linux:
sudo pacman -S libphonenumber protobuf icu
Build from source (if packages not available):
# Clone and build libphonenumber
git clone https://github.com/google/libphonenumber.git
cd libphonenumber/cpp
mkdir build && cd build
cmake ..
make -j$(nproc)
sudo make install
sudo ldconfig
Install Zig 0.15.2 or later:
# Download from https://ziglang.org/download/
# Or use your package manager
git clone <your-repo>
cd phonecheck
./build_wrapper.sh
zig build
zig build run
The API will start on http://0.0.0.0:8080
Endpoint: GET /health
Response:
{
"status": "healthy",
"service": "phonecheck",
"version": "1.0.0"
}
Endpoint: POST /validate
Request Body:
{
"phone_number": "+14155552671",
"region": "US" // Optional: ISO 3166-1 alpha-2 country code
}
Response:
{
"valid": true,
"possible": true,
"type": "FIXED_LINE_OR_MOBILE",
"country_code": 1,
"national_number": 4155552671,
"region": "US",
"e164_format": "+14155552671",
"international_format": "+1 415-555-2671",
"national_format": "(415) 555-2671",
"possibility_reason": "IS_POSSIBLE"
}
Phone Types:
FIXED_LINE - Traditional landlineMOBILE - Mobile phoneFIXED_LINE_OR_MOBILE - Could be eitherTOLL_FREE - Toll-free numberPREMIUM_RATE - Premium rate numberSHARED_COST - Shared cost serviceVOIP - VoIP numberPERSONAL_NUMBER - Personal numberPAGER - PagerUAN - Universal Access NumberVOICEMAIL - Voicemail accessUNKNOWN - Unknown typePossibility Reasons:
IS_POSSIBLE - Number is validINVALID_COUNTRY_CODE - Invalid country codeTOO_SHORT - Too few digitsTOO_LONG - Too many digitsIS_POSSIBLE_LOCAL_ONLY - Valid locally onlyINVALID_LENGTH - Invalid length for regionRun the test suite:
zig build test
# Validate a US number
curl -X POST http://localhost:8080/validate \
-H "Content-Type: application/json" \
-d '{"phone_number": "+14155552671"}'
# Validate with explicit region
curl -X POST http://localhost:8080/validate \
-H "Content-Type: application/json" \
-d '{"phone_number": "4155552671", "region": "US"}'
# International number
curl -X POST http://localhost:8080/validate \
-H "Content-Type: application/json" \
-d '{"phone_number": "+442071838750", "region": "GB"}'
import requests
def validate_phone(number: str, region: str = None):
response = requests.post(
"http://localhost:8080/validate",
json={"phone_number": number, "region": region}
)
return response.json()
# Example usage
result = validate_phone("+14155552671")
print(f"Valid: {result['valid']}")
print(f"Type: {result['type']}")
print(f"International: {result['international_format']}")
async function validatePhone(
phoneNumber: string,
region?: string
): Promise<ValidationResult> {
const response = await fetch('http://localhost:8080/validate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ phone_number: phoneNumber, region })
});
return response.json();
}
// Example usage
const result = await validatePhone('+14155552671');
console.log(`Valid: ${result.valid}`);
console.log(`Type: ${result.type}`);
โโโโโโโโโโโโโโโ
โ Client โ
โ (HTTP/JSON) โ
โโโโโโโโฌโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Zig HTTP Server โ
โ - Routing โ
โ - JSON parsing โ
โ - Error handling โ
โโโโโโโโฌโโโโโโโโโโโโโโโ
โ Zero-copy FFI
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ C++ Wrapper โ
โ - Type conversion โ
โ - Memory safety โ
โโโโโโโโฌโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ libphonenumber โ
โ - Parsing โ
โ - Validation โ
โ - Formatting โ
โโโโโโโโโโโโโโโโโโโโโโโ
Following Tiger Style principles:
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y \
libphonenumber-dev libprotobuf-dev libicu-dev
COPY zig-out/bin/phonecheck /usr/local/bin/
EXPOSE 8080
CMD ["phonecheck"]
[Unit]
Description=PhoneCheck REST API
After=network.target
[Service]
Type=simple
User=phonecheck
ExecStart=/usr/local/bin/phonecheck
Restart=always
[Install]
WantedBy=multi-user.target
The API exposes structured logs via stdout. Key metrics:
Integrate with your logging infrastructure (ELK, Loki, CloudWatch, etc.)
zig build testMIT License - See LICENSE file
Built with โค๏ธ using Zig and libphonenumber