Skip to content

Instantly share code, notes, and snippets.

@adkdev
Last active November 15, 2022 09:46
Show Gist options
  • Save adkdev/f0617721b0716dc36c975cd1ae48abc7 to your computer and use it in GitHub Desktop.
Save adkdev/f0617721b0716dc36c975cd1ae48abc7 to your computer and use it in GitHub Desktop.
Braze API Mockup for local dev
"""
Braze API Mocking (J)
> Install dependencies ->
$ pip install fastapi
$ pip install "uvicorn[standard]"
> Start server ->
$ uvicorn main:app --reload
Add more if you need :D
"""
# import random
from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.post("/users/track/")
async def get_body(request: Request):
body = await request.json()
resp = [
{
"message": "Internal server error, you should retry with exponential backoff.",
"errors": [
{
"message": "Internal server error, you should retry with exponential backoff.",
}
],
},
{
"message": "success",
"attributes_processed": len(body.get("attributes", {})),
},
]
# res = random.choice(resp) # if need to trow error randomly
res = resp[1] # always success
# if body.get("request_no", 0) > 100:
# res = resp[0] # alway error after 100
# -- for future
# "events_processed": len(body.get("events", {})),
# "purchases_processed": len(body.get("purshases", {})),
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment