Spaces:
Sleeping
Sleeping
File size: 3,117 Bytes
c8ac1ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
# Enable CORS so you can call it from a frontend or browser
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mock data: 10 fake companies
contacts = [
{
"company": "AlphaNova Inc.",
"website": "https://www.alphanova.io",
"contact": {
"name": "Alice Newton",
"email": "alice@alphanova.io",
"phone": "+1-555-1010"
}
},
{
"company": "BetaBridge Corp.",
"website": "https://www.betabridge.tech",
"contact": {
"name": "Bob Carter",
"email": "bob@betabridge.tech",
"phone": "+1-555-2020"
}
},
{
"company": "GammaWorks Ltd.",
"website": "https://www.gammaworks.net",
"contact": {
"name": "Clara West",
"email": "clara@gammaworks.net",
"phone": "+1-555-3030"
}
},
{
"company": "DeltaForge",
"website": "https://www.deltaforge.co",
"contact": {
"name": "Daniel Smith",
"email": "daniel@deltaforge.co",
"phone": "+1-555-4040"
}
},
{
"company": "EchoLane",
"website": "https://www.echolane.biz",
"contact": {
"name": "Emma Jones",
"email": "emma@echolane.biz",
"phone": "+1-555-5050"
}
},
{
"company": "ZetaPeak",
"website": "https://www.zetapeak.dev",
"contact": {
"name": "Zach Lee",
"email": "zach@zetapeak.dev",
"phone": "+1-555-6060"
}
},
{
"company": "ThetaLab",
"website": "https://www.thetalab.app",
"contact": {
"name": "Tina Ray",
"email": "tina@thetalab.app",
"phone": "+1-555-7070"
}
},
{
"company": "SigmaSoft",
"website": "https://www.sigmasoft.ai",
"contact": {
"name": "Samuel Clark",
"email": "sam@sigmasoft.ai",
"phone": "+1-555-8080"
}
},
{
"company": "OmicronTech",
"website": "https://www.omicrontech.io",
"contact": {
"name": "Olivia White",
"email": "olivia@omicrontech.io",
"phone": "+1-555-9090"
}
},
{
"company": "LambdaLogic",
"website": "https://www.lambdalogic.dev",
"contact": {
"name": "Liam Brown",
"email": "liam@lambdalogic.dev",
"phone": "+1-555-1111"
}
}
]
@app.get("/")
def root():
return {"message": "Welcome to the Fake Contact API"}
@app.get("/contacts")
def get_contacts():
return contacts
@app.get("/contacts/{company}")
def get_contact_by_company(company: str):
for contact in contacts:
if contact["company"].lower() == company.lower():
return contact
return {"error": "Company not found"}
|