🚀 Welcome to apipie
Welcome to apipie!
the syntax is easy (it is just json)
Tip: Use the navigation on the left to explore topics.
to get started, download apipie somehow
installing apipie
install it by running
pip install apipie
if you would prefer not to use a venv run
python3 -m pip install apipie
or, on windows
py -m pip install apipie
to use you can run
apipie config.json False
the first argument is the filename, or the json iteself, if you would rather just input it right into there, make the second value true, that tells the code you want to use a string not a file path
you can also run it inside a .py file
example.py
from apipie import main
main('config.json', False)
#or
main('{"some":{"json":"here"}}',True)
all you really have to do is configure it, and you do that with api_config.json
{}
in this guide we will walk you through how to configure it, all the parameters required, extra ones, and maybe even some planned ones later on
apis and nicknames
lets start with code that sends and receives our get/post request
to start lets define our api nickname
{
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get"
}
}
}
in that code above, the first value ("apis") tells us that is where all the api declarations are kept, the second value ("get_api") can have any value, that is the api nickname, and the url is where the request is sent to
now that that is defined, you can run the code, but nothing will happen, that is because we need to define the url path. it is super simple, put this at the very beginning.
{
"routes":{
"get":"get_api"
},
full code here
{
"routes":{
"get":"get_api"
},
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get"
}
}
}
go to http://localhost:8000/get, you should get a result similar to this
{
"args": {},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"Host": "httpbin.org",
"Priority": "u=0, i",
"Sec-Ch-Ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"",
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "\"Windows\"",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
"X-Amzn-Trace-Id": "Root=1-6______4-________________"
},
"origin": "--.---.--.---",
"url": "https://httpbin.org/get"
}
if you want you can change it to a post requests, and send a post request to that address if you want
{
"routes":{
"get":"get_api"
},
"apis":{
"get_api":{
"method": "post",
"url": "https://httpbin.org/post"
}
}
}
multiple routes is just as easy, just define them with a nickname, than expose that route to apipie via "routes"
{
"routes":{
"post":"post_api",
"get":"get_api",
"example/here":"example"
},
"apis":{
"post_api":{
"method": "post",
"url": "https://httpbin.org/post"
},
"get_api":{
"method": "get",
"url": "https://httpbin.org/get"
},
"example":{
"method": "get",
"url":"api.example.com/enpoint"
}
}
}
services api keys and rate limiting
you want to use a service that requires an api key, but can't expose it to the public (for obvious reasons) but want too, well here is the right place to go
api keys
it is really easy to add api keys to your apipie instance first define the api keys using the "keys" key
{
"keys":{
"api_key_identifier":"you_api_key_here"
},
it is really easy to add them to your url or whatever else
{
"routes":{
"get":"get_api"
},
"keys":{
"api_key_identifier":"you_api_key_here"
},
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get?api-key=[api_key_identifier]"
}
}
}
works with post in the same why, you can do that with headers and all that, but we will cover post later
rate limits
rate limits have two arguments, first is how many requests, second is the period of time between each refresh
{
"rate_limit": {
"limit": 3,
"window": 30
}
}
that code there has the rate limits set to 3 requests every half a minute, than it refreshes
example
{
"routes":{
"get":"get_api"
},
"keys":{
"api_key_identifier":"you_api_key_here"
},
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get?api-key=[api_key_identifier]",
"rate_limit": { "limit": 3, "window": 30 }
}
}
}
variables
there are two kinds of variables, preset ones, and path based ones
pre defined
pre defined variables is a variable that is set when the code is executed and is often not edited
{
"open-vars":{
"city": "toronto"
},
variables are easy to use time savers
like api keys, they can be placed almost anywhere easily, but use angle braces ( < and > ) instead of square braces ( [ and ] ), example
{
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get?<city>",
"rate_limit": { "limit": 3, "window": 30 }
}
}
}
easy as that
{
"routes":{
"get":"get_api"
},
"keys":{
"api_key_identifier":"you_api_key_here"
},
"open-vars":{
"city": "toronto"
},
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get?<city>&api-key=[api_key_identifier]",
"rate_limit": { "limit": 3, "window": 30 }
}
}
}
now lets do path based variables
they are super easy, just put the variable into the routes path
{
"routes":{
"city/<city>":"some_nickname"
},
and that is it, the syntax on everything else is the same
{
"routes":{
"city/<city>":"get_api"
},
"keys":{
"api_key_identifier":"you_api_key_here"
},
"apis":{
"get_api":{
"method": "get",
"url": "https://httpbin.org/get?<city>&api-key=[api_key_identifier]",
"rate_limit": { "limit": 3, "window": 30 }
}
}
}
now if you go to https://localhost:8000/city/toronto you should get
{
"args": {
"api-key": "you_api_key_here",
"toronto": ""
},
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"Host": "httpbin.org",
"Priority": "u=0, i",
"Sec-Ch-Ua": "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"",
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "\"Windows\"",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
"X-Amzn-Trace-Id": "Root=1-6______4-________________"
},
"origin": "--.---.--.---",
"url": "https://httpbin.org/get"
}
environment variables
you can use environment variables
an example on how to set on it
os.environ['SOMETHING'] = 'somevalue'
you can set it using {ENVVARIABLENAME}
like
{"url":"https://httpbin/get?{SONETHING}"}
that is it, very simple
you can set cors to true or false to block cors requests
{"cors":"false"}
that is it
authentication
authentication
Api keys
Allowed apis
Account rate limiting
no tips at the moment
no tips at the moment
this is new, so i have no idea
scripting engine
coming soon