|
| 1 | +import streamlit as st |
| 2 | + |
| 3 | +st.subheader(" API Documentation", divider="rainbow") |
| 4 | +# Custom CSS for styling |
| 5 | +st.markdown( |
| 6 | + """ |
| 7 | +<style> |
| 8 | + body { |
| 9 | + color: #333; |
| 10 | + font-family: 'Arial', sans-serif; |
| 11 | + } |
| 12 | + .faq-title { |
| 13 | + color: #FF5733; |
| 14 | + font-size: 24px; |
| 15 | + margin-top: 20px; |
| 16 | + font-weight: bold; |
| 17 | + } |
| 18 | + .code-snippet { |
| 19 | + font-family: 'Courier New', monospace; |
| 20 | + background-color: #f0f0f0; |
| 21 | + padding: 10px; |
| 22 | + border-radius: 5px; |
| 23 | + color: black; |
| 24 | + } |
| 25 | +</style> |
| 26 | +""", |
| 27 | + unsafe_allow_html=True, |
| 28 | +) |
| 29 | + |
| 30 | +# API Product Overview |
| 31 | +st.subheader("🔍 API Product Overview") |
| 32 | +st.write( |
| 33 | + "The IMDb API on AWS Data Exchange offers a GraphQL-based approach, enabling efficient data access for movie and TV series metadata, " |
| 34 | + "ratings, and box office data in real-time. It provides a streamlined JSON structure and single URL access for reduced API calls." |
| 35 | +) |
| 36 | + |
| 37 | +# Benefits |
| 38 | +st.subheader("🌟 Key Benefits") |
| 39 | +st.markdown( |
| 40 | + """ |
| 41 | + - **One Call, All Data**: Access all data via a single URL. |
| 42 | + - **Flexible Queries**: Request only the specific fields you need, minimizing data over-fetching. |
| 43 | + - **Real-time Updates**: Receive IMDb’s latest data without delay. |
| 44 | + - **Multiple Entities**: Query multiple titles/names simultaneously. |
| 45 | + """, |
| 46 | + unsafe_allow_html=True, |
| 47 | +) |
| 48 | + |
| 49 | +# Getting Access to the API |
| 50 | +st.subheader("🔑 Getting Access to the API") |
| 51 | +st.write( |
| 52 | + "To access the IMDb API, you need an AWS account and AWS Access Keys. Follow these steps to set up your access." |
| 53 | +) |
| 54 | +st.markdown( |
| 55 | + """ |
| 56 | + 1. **Create an AWS Account**: The IMDb API is available through AWS Data Exchange. |
| 57 | + 2. **Obtain AWS Access Keys**: Generate your keys for API authentication. |
| 58 | + 3. **Enable Cost Explorer (Optional)**: View your usage and cost in AWS Cost Explorer. |
| 59 | + """, |
| 60 | + unsafe_allow_html=True, |
| 61 | +) |
| 62 | + |
| 63 | +# Authentication and API Key |
| 64 | +st.subheader("🔒 Authentication and API Key") |
| 65 | +st.write( |
| 66 | + "For API calls, the `x-api-key` header must include your API Key. Authenticate requests using AWS credentials in one of the following ways." |
| 67 | +) |
| 68 | + |
| 69 | +# Code Snippet for AWS CLI |
| 70 | +st.markdown( |
| 71 | + """ |
| 72 | + **Example API Call (AWS CLI)**: |
| 73 | + """, |
| 74 | + unsafe_allow_html=True, |
| 75 | +) |
| 76 | +st.code( |
| 77 | + """ |
| 78 | +aws dataexchange send-api-asset \\ |
| 79 | +--data-set-id <Dataset ID> \\ |
| 80 | +--revision-id <Revision ID> \\ |
| 81 | +--asset-id <Asset ID> \\ |
| 82 | +--request-headers "{ 'x-api-key': '<Your API Key>'}" \\ |
| 83 | +--region us-east-1 \\ |
| 84 | +--body "{ 'query': '{ title(id: \"tt0120338\") { ratingsSummary { aggregateRating voteCount } } }' }" |
| 85 | + """, |
| 86 | + language="bash", |
| 87 | +) |
| 88 | + |
| 89 | +# Sample GraphQL Query |
| 90 | +st.subheader("💻 Sample Query") |
| 91 | +st.write("Here’s a sample GraphQL query to retrieve the IMDb rating for *Titanic*:") |
| 92 | + |
| 93 | +st.markdown( |
| 94 | + """ |
| 95 | +<div class="code-snippet"> |
| 96 | +{ |
| 97 | + title(id: "tt0120338") { |
| 98 | + ratingsSummary { |
| 99 | + aggregateRating |
| 100 | + voteCount |
| 101 | + } |
| 102 | + } |
| 103 | +} |
| 104 | +</div> |
| 105 | +""", |
| 106 | + unsafe_allow_html=True, |
| 107 | +) |
| 108 | + |
| 109 | +# Response Example |
| 110 | +st.subheader("📊 Sample API Response") |
| 111 | +st.write('{\n "data": {\n "title": {\n "ratingsSummary": {') |
| 112 | +st.write(' "aggregateRating": 7.9,\n "voteCount": 1133828') |
| 113 | +st.write(" }\n }\n }\n}") |
| 114 | + |
| 115 | +# Additional Code Snippets |
| 116 | +st.subheader("📜 Additional Code Snippets") |
| 117 | + |
| 118 | +# Code Snippet for Postman Request |
| 119 | +st.write("**Making Requests via Postman**") |
| 120 | +st.markdown( |
| 121 | + """ |
| 122 | +1. **Set Method**: Use `POST` method. |
| 123 | +2. **Request URL**: `https://api-fulfill.dataexchange.us-east-1.amazonaws.com/v1` |
| 124 | +3. **Headers**: |
| 125 | + - `Content-Type`: `application/json` |
| 126 | + - `x-api-key`: `<Your API Key>` |
| 127 | +4. **Body (GraphQL Query)**: |
| 128 | + ```graphql |
| 129 | + { |
| 130 | + title(id: "tt0120338") { |
| 131 | + ratingsSummary { |
| 132 | + aggregateRating |
| 133 | + voteCount |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + ``` |
| 138 | + """, |
| 139 | + unsafe_allow_html=True, |
| 140 | +) |
| 141 | + |
| 142 | +# Code Snippet for Python API Call |
| 143 | +st.write("**Python Code to Make an API Call**") |
| 144 | +st.code( |
| 145 | + """ |
| 146 | +import requests |
| 147 | +
|
| 148 | +url = "https://api-fulfill.dataexchange.us-east-1.amazonaws.com/v1" |
| 149 | +headers = { |
| 150 | + "x-api-key": "<Your API Key>", |
| 151 | + "Content-Type": "application/json" |
| 152 | +} |
| 153 | +query = ''' |
| 154 | +{ |
| 155 | + title(id: "tt0120338") { |
| 156 | + ratingsSummary { |
| 157 | + aggregateRating |
| 158 | + voteCount |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | +''' |
| 163 | +response = requests.post(url, headers=headers, data=query) |
| 164 | +print(response.json()) |
| 165 | +""", |
| 166 | + language="python", |
| 167 | +) |
| 168 | + |
| 169 | +# Example Use Cases |
| 170 | +st.subheader("📄 Example Use Cases") |
| 171 | +st.markdown( |
| 172 | + """ |
| 173 | +1. **Retrieve Ratings**: Query title ratings and vote counts. |
| 174 | +2. **Box Office Data**: Access box office gross data. |
| 175 | +3. **Cast and Crew**: Fetch top cast or crew details for movies and shows. |
| 176 | +4. **Search Functionality**: Use keywords to find specific titles or names. |
| 177 | +5. **Real-time Data Access**: Display data updates as they become available on IMDb. |
| 178 | +""", |
| 179 | + unsafe_allow_html=True, |
| 180 | +) |
| 181 | + |
| 182 | +# Footer |
| 183 | +st.markdown("---") |
| 184 | +st.markdown( |
| 185 | + "<small>For further assistance, contact support at [email protected]</small>", |
| 186 | + unsafe_allow_html=True, |
| 187 | +) |
0 commit comments