Skip to content

Commit

Permalink
remvoe api key check
Browse files Browse the repository at this point in the history
  • Loading branch information
umuterturk committed Feb 17, 2025
1 parent 5b93e55 commit 175e01b
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 31 deletions.
8 changes: 0 additions & 8 deletions internal/middleware/rapidapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ func NewRapidAPIAuthMiddleware(next http.Handler, proxySecret string) http.Handl
return
}

// Check other RapidAPI headers
rapidAPIKey := r.Header.Get("X-RapidAPI-Key")
if rapidAPIKey == "" {
http.Error(w, "Missing RapidAPI key", http.StatusUnauthorized)
return
}

// You can add additional validation here if needed
next.ServeHTTP(w, r)
})
}
Expand Down
8 changes: 4 additions & 4 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ servers:
description: Local development

security:
- RapidAPIKey: []
- RapidAPISecret: []

components:
securitySchemes:
RapidAPIKey:
RapidAPISecret:
type: apiKey
in: header
name: X-RapidAPI-Key
description: RapidAPI subscription key for authentication
name: X-RapidAPI-Secret
description: RapidAPI proxy secret for authentication

schemas:
EmailValidationRequest:
Expand Down
190 changes: 190 additions & 0 deletions rapidapi-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# Email Validator API Overview

This document provides a comprehensive overview of the Email Validator API endpoints available through RapidAPI.

## Base URL
```
https://email-validator.p.rapidapi.com
```

## Authentication
All API requests require the following headers:
- `X-RapidAPI-Host`: email-validator.p.rapidapi.com
- `X-RapidAPI-Secret`: Your RapidAPI proxy secret

## Endpoints

### 1. Validate Single Email
Validates a single email address and returns detailed validation results.

**Endpoint:** `/validate`

**Methods:** GET, POST

#### GET Request
```
GET /[email protected]
```

#### POST Request
```json
{
"email": "[email protected]"
}
```

#### Response
```json
{
"email": "[email protected]",
"validations": {
"syntax": true,
"domain_exists": true,
"mx_records": true,
"is_disposable": false,
"is_role_based": false
},
"score": 100,
"status": "VALID"
}
```

#### Possible Status Values
- `VALID`: Email is valid and deliverable
- `PROBABLY_VALID`: Email is probably valid but has some issues
- `INVALID`: Email has significant validation issues
- `MISSING_EMAIL`: No email was provided
- `INVALID_FORMAT`: Invalid email format
- `INVALID_DOMAIN`: Domain does not exist
- `NO_MX_RECORDS`: Domain cannot receive emails
- `DISPOSABLE`: Disposable email address detected

### 2. Batch Email Validation
Validates multiple email addresses in a single request.

**Endpoint:** `/validate/batch`

**Methods:** GET, POST

#### GET Request
```
GET /validate/[email protected]&[email protected]
```

#### POST Request
```json
{
"emails": [
"[email protected]",
"[email protected]"
]
}
```

#### Response
```json
{
"results": [
{
"email": "[email protected]",
"validations": {
"syntax": true,
"domain_exists": true,
"mx_records": true,
"is_disposable": false,
"is_role_based": false
},
"score": 100,
"status": "VALID"
},
{
"email": "[email protected]",
"validations": {
"syntax": true,
"domain_exists": true,
"mx_records": true,
"is_disposable": false,
"is_role_based": true
},
"score": 80,
"status": "PROBABLY_VALID"
}
]
}
```

### 3. Typo Suggestions
Get suggestions for possible typos in email addresses.

**Endpoint:** `/typo-suggestions`

**Methods:** GET, POST

#### GET Request
```
GET /[email protected]
```

#### POST Request
```json
{
"email": "[email protected]"
}
```

#### Response
```json
{
"email": "[email protected]",
"suggestions": [
"[email protected]",
"[email protected]"
]
}
```

### 4. API Status
Check the current status and performance metrics of the API.

**Endpoint:** `/status`

**Method:** GET

#### Response
```json
{
"status": "operational",
"uptime": "99.99%",
"requests_handled": 1000000,
"average_response_time_ms": 150.5
}
```

## Error Responses
When an error occurs, the API will return an error response with an appropriate HTTP status code:

```json
{
"error": "Error message describing what went wrong"
}
```

Common HTTP status codes:
- `400 Bad Request`: Invalid input or missing parameters
- `401 Unauthorized`: Invalid or missing API key
- `403 Forbidden`: Exceeded API quota or unauthorized access
- `429 Too Many Requests`: Rate limit exceeded
- `500 Internal Server Error`: Server-side error

## Rate Limiting
The API implements rate limiting based on your RapidAPI subscription plan. When you exceed the rate limit, you'll receive a 429 status code.

## Best Practices
1. Always check the validation status and score to make decisions
2. Handle disposable email addresses according to your use case
3. Implement proper error handling for all possible status codes
4. Cache validation results when appropriate
5. Use batch validation for multiple email checks to improve performance

## Support
For API support and questions, please contact through RapidAPI's support channels or visit the documentation page on RapidAPI.com.
2 changes: 0 additions & 2 deletions tests/integration/handlers_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ var (
)

const (
testRapidAPIKey = "test-api-key"
testRapidAPISecret = "test-secret"
)

func addRapidAPIHeaders(req *http.Request) {
req.Header.Set("X-RapidAPI-Key", testRapidAPIKey)
req.Header.Set("X-RapidAPI-Secret", testRapidAPISecret)
}

Expand Down
18 changes: 1 addition & 17 deletions tests/integration/rapidapi_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,49 +27,36 @@ func TestRapidAPIAuthMiddleware(t *testing.T) {

tests := []struct {
name string
rapidAPIKey string
proxySecret string
skipSecret string
expectedStatus int
}{
{
name: "Valid headers",
rapidAPIKey: "valid-api-key",
name: "Valid proxy secret",
proxySecret: expectedSecret,
skipSecret: "",
expectedStatus: http.StatusOK,
},
{
name: "Missing RapidAPI Key",
rapidAPIKey: "",
proxySecret: expectedSecret,
skipSecret: "",
expectedStatus: http.StatusUnauthorized,
},
{
name: "Invalid proxy secret",
rapidAPIKey: "valid-api-key",
proxySecret: "invalid-secret",
skipSecret: "",
expectedStatus: http.StatusUnauthorized,
},
{
name: "Missing proxy secret",
rapidAPIKey: "valid-api-key",
proxySecret: "",
skipSecret: "",
expectedStatus: http.StatusUnauthorized,
},
{
name: "Valid skip secret bypasses RapidAPI checks",
rapidAPIKey: "",
proxySecret: "",
skipSecret: skipSecret,
expectedStatus: http.StatusOK,
},
{
name: "Invalid skip secret",
rapidAPIKey: "",
proxySecret: "",
skipSecret: "invalid-skip-secret",
expectedStatus: http.StatusUnauthorized,
Expand All @@ -83,9 +70,6 @@ func TestRapidAPIAuthMiddleware(t *testing.T) {
req := httptest.NewRequest("GET", "/test", nil)

// Set headers
if tt.rapidAPIKey != "" {
req.Header.Set("X-RapidAPI-Key", tt.rapidAPIKey)
}
if tt.proxySecret != "" {
req.Header.Set("X-RapidAPI-Secret", tt.proxySecret)
}
Expand Down

0 comments on commit 175e01b

Please sign in to comment.