NJ Municipality Lookup
CodebaseSrcApp(app)

Test Api

Development interface for testing NJ OGIS geocoding and suggestions APIs with custom parameters and viewing raw responses.

API Testing Page (app/test-api/)

Development interface for testing NJ OGIS geocoding and suggestions APIs with custom parameters and viewing raw responses.

Purpose

Provides developers with tools to:

  1. Test NJ geocoding API directly with custom parameters
  2. Test NJ suggestions API with various queries
  3. View raw API responses (JSON)
  4. Debug integration issues
  5. Validate API behavior for edge cases

Route

/test-api - API Testing Interface

⚠️ Development Tool: This page is intended for development and testing. Consider restricting access in production.

Features

Geocoding API Tester

Test the NJ OGIS geocoding endpoint:

interface GeocodingTestParams {
  address: string; // Full address to geocode
  format: "json" | "pjson"; // Response format
  outFields?: string; // Comma-separated field names
  outSR?: string; // Spatial reference (e.g., "4326")
}

UI Controls:

  • Address input field
  • Format selector (JSON / PJSON)
  • Optional parameters panel
  • "Test Geocoding" button

Output:

  • HTTP status code
  • Response time (ms)
  • Raw JSON response
  • Formatted result preview

Suggestions API Tester

Test the NJ OGIS suggestions endpoint:

interface SuggestionsTestParams {
  query: string; // Partial address query
  maxResults: number; // Maximum suggestions (1-20)
  location?: string; // Bias location (lat,lon)
  distance?: number; // Search radius (meters)
}

UI Controls:

  • Query input field
  • Max results slider (1-20)
  • Optional location bias
  • "Test Suggestions" button

Output:

  • HTTP status code
  • Response time (ms)
  • Raw JSON response
  • Suggestion count

UI Layout

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ NJ API Testing Interface            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ [Geocoding] [Suggestions]           β”‚ ← Tabs
β”‚                                     β”‚
β”‚ Geocoding API Test                  β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Address: [                    ] β”‚ β”‚
β”‚ β”‚ Format:  [JSON β–Ό]               β”‚ β”‚
β”‚ β”‚ [β–Ά Additional Options]          β”‚ β”‚
β”‚ β”‚ [Test Geocoding]                β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                     β”‚
β”‚ Response (234ms)                    β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Status: 200 OK                  β”‚ β”‚
β”‚ β”‚ {                               β”‚ β”‚
β”‚ β”‚   "location": { ... },          β”‚ β”‚
β”‚ β”‚   "attributes": { ... }         β”‚ β”‚
β”‚ β”‚ }                               β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ [Copy Response] [Download JSON]    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Server Actions

Page calls testing server actions:

import {
  testGeocodingApi,
  testSuggestionsApi,
} from "@/app/actions/api-testing";

// Test geocoding
const result = await testGeocodingApi({
  address: "323 Dr MLK Jr Blvd, Newark, NJ",
  format: "json",
});

// Test suggestions
const suggestions = await testSuggestionsApi({
  query: "323",
  maxResults: 10,
});

Response Display

Success Response

{
  "status": 200,
  "responseTime": 234,
  "data": {
    "candidates": [
      {
        "address": "323 DR MARTIN LUTHER KING JR BLVD, NEWARK, NJ, 07102",
        "location": {
          "x": -74.175383,
          "y": 40.740623
        },
        "score": 100,
        "attributes": {
          "Loc_name": "PointAddress",
          "Status": "M",
          "Score": 100,
          "Match_addr": "323 DR MARTIN LUTHER KING JR BLVD, NEWARK, NJ, 07102",
          "City": "NEWARK",
          "Subregion": "ESSEX",
          "Region": "New Jersey",
          "Postal": "07102"
        }
      }
    ]
  }
}

Error Response

{
  "status": 400,
  "responseTime": 125,
  "error": "Invalid address parameter"
}

Use Cases

Debug Integration Issues

When address lookup fails in production:

  1. Open API tester
  2. Enter exact same address
  3. View raw API response
  4. Identify API-level vs application-level issue

Test Edge Cases

Validate handling of:

  • Empty addresses
  • Addresses with special characters
  • Very long addresses
  • Addresses outside New Jersey
  • Ambiguous addresses (multiple matches)

API Behavior Exploration

Understand how NJ API handles:

  • Different address formats
  • Abbreviations vs full names
  • Case sensitivity
  • Extra spaces or punctuation
  • Missing components (city, ZIP)

Performance Benchmarking

Measure API response times:

  • Compare cached vs uncached
  • Test with different address types
  • Identify slow queries

Example Test Scenarios

Scenario 1: Valid Address

Input:

  • Address: "323 Dr Martin Luther King Jr Blvd, Newark, NJ 07102"
  • Format: JSON

Expected:

  • Status: 200
  • Response Time: ~200-500ms
  • Match Score: 100
  • Municipality: Newark

Scenario 2: Ambiguous Address

Input:

  • Address: "Main Street, NJ"
  • Format: JSON

Expected:

  • Status: 200
  • Multiple candidates returned
  • Lower match scores
  • Different municipalities

Scenario 3: Invalid Address

Input:

  • Address: "123 Nonexistent St, Nowhere, NJ"
  • Format: JSON

Expected:

  • Status: 200 (API always returns 200)
  • Empty candidates array
  • No results

Scenario 4: Suggestions Test

Input:

  • Query: "323 Dr"
  • Max Results: 5

Expected:

  • Status: 200
  • Response Time: ~100-300ms
  • 5 or fewer suggestions
  • All contain "323 Dr"

Security Considerations

⚠️ Access Control: This page exposes raw API functionality. Consider:

  • Restricting to development environment only
  • Adding authentication for production access
  • Rate limiting to prevent abuse
  • Logging all test requests

Accessibility

  • Form Labels: All inputs properly labeled
  • Error Messages: Screen reader announcements
  • Keyboard Navigation: Tab through all controls
  • Response Readability: Syntax-highlighted JSON

Responsive Design

  • Mobile: Vertical layout, scrollable response
  • Tablet: Split view for inputs and response
  • Desktop: Side-by-side comparison view

Testing

API tester page is tested with:

  1. Unit Tests: Component rendering and form submission
  2. Integration Tests: Server action calls to test APIs
  3. E2E Tests: Playwright tests for full workflow

Performance

  • Initial Load: Minimal (no API calls on page load)
  • Test Execution: Depends on NJ API response time
  • Response Display: Syntax highlighting may be slow for large responses

Future Enhancements

Potential additions:

  • Request History: Save and replay previous tests
  • Batch Testing: Test multiple addresses at once
  • Diff Viewer: Compare responses across API versions
  • Share Results: Generate shareable links for bug reports
  • Export: Download test results as CSV or JSON

On this page