How can I use Fetch JSON Plugin

I have tried following the example of Plugin Fetch JSON and found that it works like the example provided.

But when I experimented with other links returned an empty result. I want to know why this is the case.

worldtimeapi.org/api/timezone/Asia/Tokyo

You should always use https instead of http for fetching APIs from Glide, just to be sure.

4 Likes

Thank you for the advice @ThinhDinh
I still have a few questions.

I’ve tried building an API from FastAPI using Heroku’s host.
After building I tried running it through Browser.
I think it should work normally.

https://myapi1123344.herokuapp.com/joke/
https://myapi1123344.herokuapp.com/book/

But when applied to columns, it doesn’t show any results.

Do you have any advice for me?

This is my main.py

from typing import Optional
from fastapi import FastAPI
app = FastAPI()
book_db = [
    {
        "title":"The C Programming",
        "price": 720
    },
    {
        "title":"Learn Python the Hard Way",
        "price": 870
    },
    {
        "title":"JavaScript: The Definitive Guide",
        "price": 1369
    },
    {
        "title":"Python for Data Analysis",
        "price": 1394
    },
    {
        "title":"Clean Code",
        "price": 1500
    },
]
joke_db = [
    {
        "id":487,
        "joke":"No statement can catch the ChuckNorrisException.",
        "categories":["nerdy"]
    },
    {
        "id":176,
        "joke":"According to Einstein's theory of relativity, Chuck Norris can actually roundhouse kick you yesterday.",
        "categories":[]
    },
    {
        "id":536,
        "joke":"Don't worry about tests, Chuck Norris's test cases cover your code too.",
        "categories":["nerdy"]
    }
]
@app.get("/")
def read_root():
    return {"Hello": "Worldbb"}
@app.get("/book/")
async def get_books():
    ans = {"type":"success","value":book_db}
    return ans
@app.get("/joke/")
async def get_jokes():
    ans = {"type":"success","value":joke_db}
    return ans

I have no idea how FastAPI and Heroku would integrate with Glide, but in my experience, if clicking the link would generate some response then it’s either a CORS problem or that it took too much time (more than the timeout set by Glide?) to generate a response in the app.

@ThinhDinh Thank you very much.

1 Like

The plugin does not handle JSON arrays. You could try something with the JQuery part of it but frankly, I am not an expert at JSON so don’t know what to tell you there. Here is a list of other free APIs that return JSON. Maybe by looking at a few others that do work you may be able to structure your return JSON to something that does work.

1 Like

Thank you very much

@George-Glide
I choose Bored Activity suggestions https://www.boredapi.com/api/activity
from your example.
This is result
{“activity”:“Write a poem”,“type”:“recreational”,“participants”:1,“price”:0,“link”:"",“key”:“8688620”,“accessibility”:0}

I put it into my FastAPI but result still empty.

@david I saw your api https://cat-fact.herokuapp.com/facts
I want to know How you setting your api using with Glide App?

Thank you @ThinhDinh

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware


app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*']
)

@app.get('/')
def read_main():
    return {'message': 'Hello World!'}
1 Like

This solved the CORS problem? Sweet!