Я пытаюсь создать REST API отсюда https://api.psychonautwiki.org/ для обеспечения безопасности на моем сервере разногласий. Я довольно новичок в REST API и сводил меня с ума, пытаясь понять, как заставить это работать.
вот код, с которым я пытался:
const Discord = require('discord.js');
const fetch = require('node-fetch');
const querystring = require('querystring');
module.exports = {
name: 'dinfo',
definition: 'its a secret',
},
module.exports.execute = async (message, args) => {
if (!message.member.hasPermission("ADMINISTRATOR")) {
return message.reply('you dont have access to this')
}
if (!args.length) {
return message.reply('require search term');
}
const query = querystring.stringify({ term: args[2].join(' ') });
const { list } = await fetch(`https://api.psychonautwiki.org/`).then(response => response.json());
if (!list.length) {
return message.channel.send(`No info found for **${args.join(' ')}**.`);
}
const [answer] = list;
channel.message.send("```" + list + "```");
}
это часть того, что предоставляет API (без понятия, что с ним делать или даже нужно ли это):
substances(query: " ") {
name
# routes of administration
roas {
name
dose {
units
threshold
heavy
common { min max }
light { min max }
strong { min max }
}
duration {
afterglow { min max units }
comeup { min max units }
duration { min max units }
offset { min max units }
onset { min max units }
peak { min max units }
total { min max units }
}
bioavailability {
min max
}
}
# subjective effects
effects {
name url
}
}
}
любая помощь, чтобы двигаться дальше от этого чрезвычайно ценится!
Редактировать: вот завиток:
heres the curl ```curl 'type Effect { name: String url: String substances: [Substance] experiences: [Experience] } type Experience { substances: [Substance] effects: [Experience] } type Query { substances( effect: String query: String chemicalClass: String psychoactiveClass: String limit: Int = 10 offset: Int = 0 ): [Substance] effects( effect: String substance: String limit: Int = 50 offset: Int = 0 ): [Substance] @deprecated( reason: "This node will be removed soon. In order to fetch effect related information, use the specific nodes `substances_by_effect` or `effects_by_substance` instead." ) substances_by_effect( effect: [String] limit: Int = 50 offset: Int = 0 ): [Substance] effects_by_substance( substance: String limit: Int = 50 offset: Int = 0 ): [Effect] experiences( substances_by_effect: String effects_by_substance: String substance: String ): [Experience] } interface RoaRange { min: Float max: Float } type Substance { name: String url: String featured: Boolean effects: [Effect] experiences: [Experience] class: SubstanceClass tolerance: SubstanceTolerance roa: SubstanceRoaTypes roas: [SubstanceRoa] summary: String images: [SubstanceImage] addictionPotential: String toxicity: [String] crossTolerances: [String] uncertainInteractions: [Substance] unsafeInteractions: [Substance] dangerousInteractions: [Substance] } type SubstanceClass { chemical: [String] psychoactive: [String] } type SubstanceImage { thumb: String image: String } type SubstanceRoa { name: String dose: SubstanceRoaDose duration: SubstanceRoaDuration bioavailability: SubstanceRoaRange } type SubstanceRoaDose { units: String threshold: Float heavy: Float common: SubstanceRoaRange light: SubstanceRoaRange strong: SubstanceRoaRange } type SubstanceRoaDuration { afterglow: SubstanceRoaDurationRange comeup: SubstanceRoaDurationRange duration: SubstanceRoaDurationRange offset: SubstanceRoaDurationRange onset: SubstanceRoaDurationRange peak: SubstanceRoaDurationRange total: SubstanceRoaDurationRange } type SubstanceRoaDurationRange implements RoaRange { min: Float max: Float units: String } type SubstanceRoaRange implements RoaRange { min: Float max: Float } type SubstanceRoaTypes { oral: SubstanceRoa sublingual: SubstanceRoa buccal: SubstanceRoa insufflated: SubstanceRoa rectal: SubstanceRoa transdermal: SubstanceRoa subcutaneous: SubstanceRoa intramuscular: SubstanceRoa intravenous: SubstanceRoa smoked: SubstanceRoa } type SubstanceTolerance { full: String half: String zero: String }' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: https://api.psychonautwiki.org' --data-binary '{"query":"{\n # Welcome to the PsychonautWiki API!\n #\n # To learn more about individual fields,\n # keep 'ctrl' (Windows) or 'cmd' (macOS)\n # pressed and click the field name. This\n # will open the respective documentation\n # entry in a sidebar on the right.\n #\n # If you have any questions or found an\n # issue or any bug, don't hesitate to\n # contact Kenan (kenan@psy.is).\n #\n # Happy hacking!\n\n substances(query: args {\n name\n\n # routes of administration\n roas {\n name\n\n dose {\n units\n threshold\n heavy\n common {\n min\n max\n }\n light {\n min\n max\n }\n strong {\n min\n max\n }\n }\n\n duration {\n afterglow {\n min\n max\n units\n }\n comeup {\n min\n max\n units\n }\n duration {\n min\n max\n units\n }\n offset {\n min\n max\n units\n }\n onset {\n min\n max\n units\n }\n peak {\n min\n max\n units\n }\n total {\n min\n max\n units\n }\n }\n\n bioavailability {\n min\n max\n }\n }\n\n # subjective effects\n effects {\n name\n url\n }\n }\n}\n"}' --compressed```