{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1a3959ca-cacd-4c35-b92c-d44b8b5031dd",
   "metadata": {},
   "source": [
    "# Print Response Information\n",
    "\n",
    "The following cell defines a function that makes queries to a service and prints out information about the response to that query. You will not  need to change the code in this cell.\n",
    "\n",
    "Run the cell to create this function. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ed773b4-8fee-4504-9d52-f1d8bd33ad81",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "\n",
    "def printResponseInfo(queryURL, numFeatures, cacheHint, resultType):\n",
    "    params = {\n",
    "        \"where\": f\"objectid<{numFeatures}\",\n",
    "        \"cacheHint\": cacheHint,\n",
    "        \"resultType\": resultType,\n",
    "        \"f\": \"json\",\n",
    "        \"outfields\": \"*\",\n",
    "    }\n",
    "    releventHeaders = {\"Date\", \"x-esri-cache-hint-features\", \"x-esri-ftiles-cache-compress\"}\n",
    "    \n",
    "    r = requests.get(f\"{queryURL}\", params)\n",
    "    print(f\"Status code: {r.status_code}\")\n",
    "    for k, v in r.headers.items():\n",
    "        if k in releventHeaders:\n",
    "            print(f\"{k}: {v}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d02bcf55-1bd5-429f-a057-b5d2e3dae4fc",
   "metadata": {},
   "source": [
    "The following cell provides some values and calls the function with those values. You can change the values in this cell to experiment with how response caching works."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b008d434-4c2c-46d8-a375-3cceaf21d3d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "queryURL = \"https://example.com/server/rest/services/Hosted/FrogHabitat/FeatureServer/0/query\"\n",
    "resultType = \"\"\n",
    "cacheHint = \"false\"\n",
    "numFeatures = 1\n",
    "\n",
    "printResponseInfo(queryURL, numFeatures, cacheHint, resultType)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
