http://127.0.0.1:8000
- Interactive Docs: http://127.0.0.1:8000/docs
- Full Documentation: API_DOCUMENTATION.md
| Method | Endpoint | Purpose | Auth Required |
|---|---|---|---|
| POST | /ask |
Ask questions about market | No |
| GET | /product/search?q={query} |
Search for products | No |
| GET | /line/info/{line_name} |
Get line details | No |
| GET | /history |
Get market history | No |
| POST | /voice/query |
Voice query (audio in/out) | No |
| POST | /image/identify |
Identify product from image | No |
| GET | /navigate?line_name={name} |
Get directions to line | No |
curl -X POST "http://127.0.0.1:8000/ask" \
-H "Content-Type: application/json" \
-d '{"question": "Where can I buy shoes?"}'fetch('http://127.0.0.1:8000/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ question: 'Where can I buy shoes?' })
})
.then(res => res.json())
.then(data => console.log(data));Response:
{
"answer": "Found 'shoes' in the following lines: Blessed Line, Victory Line, Wisdom Line, Godly Line.",
"source": "local",
"images": ["/images/Blessed Lines.jpg", "/images/Victory line.jpg"]
}curl "http://127.0.0.1:8000/product/search?q=clothes"fetch('http://127.0.0.1:8000/product/search?q=clothes')
.then(res => res.json())
.then(data => console.log(data.results));Response:
{
"query": "clothes",
"results": [
{
"line_name": "Best Line",
"items_sold": ["pharmacies", "clothes", "wine", "bodystuff"],
"layout": { "column": "left", "order": 5 }
}
]
}curl "http://127.0.0.1:8000/line/info/Victory%20Line"fetch('http://127.0.0.1:8000/line/info/Victory Line')
.then(res => res.json())
.then(data => console.log(data));Response:
{
"line_name": "Victory Line",
"items_sold": ["beads", "jewelries", "clothes", "babystuff", "shoes"],
"layout": { "column": "right", "order": 5 },
"image_url": "/images/Victory line.jpg"
}curl "http://127.0.0.1:8000/navigate?line_name=Victory%20Line"fetch('http://127.0.0.1:8000/navigate?line_name=Victory Line')
.then(res => res.json())
.then(data => console.log(data.directions));Response:
{
"line_name": "Victory Line",
"directions": "Go to the RIGHT column, it's the 5th line on that side.",
"layout": { "column": "right", "order": 5 }
}curl "http://127.0.0.1:8000/history"fetch('http://127.0.0.1:8000/history')
.then(res => res.json())
.then(data => console.log(data.history));// Record audio or get audio file
const formData = new FormData();
formData.append('file', audioBlob, 'query.wav');
fetch('http://127.0.0.1:8000/voice/query', {
method: 'POST',
body: formData
})
.then(res => res.blob())
.then(blob => {
const audio = new Audio(URL.createObjectURL(blob));
audio.play();
});// Get image from file input
const formData = new FormData();
formData.append('file', imageFile);
fetch('http://127.0.0.1:8000/image/identify', {
method: 'POST',
body: formData
})
.then(res => res.json())
.then(data => console.log(data));{
"field1": "value",
"field2": ["array", "values"]
}{
"detail": "Error message here"
}200- Success400- Bad Request (invalid input)404- Not Found (line doesn't exist)422- Validation Error500- Server Error
- Mothers Line - medicine, babystuff, cookedfood
- Family Line - drinks, fowlfeed, toothpaste, ropesandbags, sleepers
- Magazine Line - pharmacies, bodylotion, drinks(egwine)
- Onitsha Line - cosmetics, wine, fewpharmacies
- Best Line - pharmacies, clothes, wine, bodystuff
- Fish Line - dryfish
- Obama Line - medicine, kitchenutensils, wigs
- Peaceful Line - babystuff, pharmacy, wine
- Blessed Line - shoes, boxes, buckets, kitchenutensils
- Victory Line - beads, jewelries, clothes, babystuff, shoes, wigs, baggyjeans, bodylotion, schoolequipment
- Universal Line - clothes, sleepers, bags, kitchenutensils, hair, wigs
- Fashion Line - clothes, sportwears, bodystuff, mesh, rainboots
- Wisdom Line - clothes, bags, shoes, sleepers, kitchenutensils
- Godly Line - shoes, dresses, roomdecoitems, bags, babystuff
- Rapa Line - (no items listed)
// Request Types
interface AskRequest {
question: string;
}
// Response Types
interface AskResponse {
answer: string;
source: 'local' | 'online' | 'combined';
images: string[];
}
interface ProductSearchResponse {
query: string;
results: Line[];
}
interface Line {
line_name: string;
items_sold: string[];
layout: {
column: 'left' | 'right';
order: number;
};
}
interface LineInfoResponse extends Line {
image_url: string | null;
}
interface NavigateResponse {
line_name: string;
directions: string;
layout: {
column: 'left' | 'right';
order: number;
};
}
interface HistoryResponse {
history: string;
}import { useState } from 'react';
const API_BASE = 'http://127.0.0.1:8000';
// Hook for asking questions
export function useAsk() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const ask = async (question: string) => {
setLoading(true);
setError(null);
try {
const res = await fetch(`${API_BASE}/ask`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ question })
});
if (!res.ok) throw new Error('Failed to get answer');
return await res.json();
} catch (err) {
setError(err.message);
throw err;
} finally {
setLoading(false);
}
};
return { ask, loading, error };
}
// Hook for product search
export function useProductSearch() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const search = async (query: string) => {
setLoading(true);
setError(null);
try {
const res = await fetch(
`${API_BASE}/product/search?q=${encodeURIComponent(query)}`
);
if (!res.ok) throw new Error('Search failed');
return await res.json();
} catch (err) {
setError(err.message);
throw err;
} finally {
setLoading(false);
}
};
return { search, loading, error };
}
// Usage in component
function SearchComponent() {
const { search, loading } = useProductSearch();
const [results, setResults] = useState([]);
const handleSearch = async (query: string) => {
const data = await search(query);
setResults(data.results);
};
return (
<div>
<input onChange={(e) => handleSearch(e.target.value)} />
{loading && <p>Loading...</p>}
{results.map(line => <div key={line.line_name}>{line.line_name}</div>)}
</div>
);
}Visit http://127.0.0.1:8000/docs to test endpoints directly in your browser.
Quick command-line testing:
# Test if API is running
curl http://127.0.0.1:8000/history
# Test product search
curl "http://127.0.0.1:8000/product/search?q=shoes"Import the provided Postman collection for easy testing.
Use the Network tab to inspect requests and responses.
// Wrong
fetch(`/line/info/Victory Line`)
// Correct
fetch(`/line/info/${encodeURIComponent('Victory Line')}`)// Wrong
fetch('/ask', {
method: 'POST',
body: JSON.stringify({ question: 'test' })
})
// Correct
fetch('/ask', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ question: 'test' })
})// Wrong (for /ask endpoint)
const formData = new FormData();
formData.append('question', 'test');
// Correct
const body = JSON.stringify({ question: 'test' });// Correct (for /voice/query and /image/identify)
const formData = new FormData();
formData.append('file', fileBlob, 'filename.wav');- Full Documentation: See API_DOCUMENTATION.md
- Interactive Testing: http://127.0.0.1:8000/docs
- Backend README: backend/README.md