Как выполнять запросы в GraphQL API
Как выполнять запросы к API
curl -X POST \ -H "Content-Type: application/json" \ -d '{"query": "{ searchPlaces(query: \"москва\", size: 1) { id name_ru name_en population } }"}' \ https://hub.youthink.io/graphql{ "data":{ "searchPlaces":[ { "id":26, "name_ru":"Москва", "name_en":"Moscow", "population":12615279 } ] } }const apiToken = '<token-...>'; fetch('https://hub.youthink.io/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', authorization: `Bearer ${apiToken}` }, body: JSON.stringify({ query: ` query SearchPlaces($search: String!, $size: Float = 300) { searchPlaces(query: $search, size: $size) { id name_ru name_en population } } `, variables: { size: 1, search: 'Москва' } }) }).then(r => r.json()).then(data => console.log('data returned:', data));
Last updated