Javascript: Code Samples For Using Magic-Summary
Getting Started
Computational Magic, including Magic-Summary, use GraphQL - if you are not yet familiar with GraphQL, we highly recommend HowToGraphQL.
The code samples below are supposed to provide a quick and easy way to get started with the Magic-Summary API in Computational Magic. Just copy the code, replace the placeholder with your own API key, pass in your strings you want to summarise (for example using templating with string literals in Javascript) and get going.
Replace API key and content with your own
Please be sure to replace the placeholder API key with your API key and pass in your own strings for summarisation.
Isomorphic Fetch
This is an exmaple of how to use fetch
to call the Magic-Summary API.
fetch('https://beta.eu-north.computational-magic.com/api/v1', {method: 'POST',headers: { 'x-api-key': 'YOUR API KEY HERE', 'Content-Type': 'application/json' },body: JSON.stringify({ query: `query {summary(input: "YOUR LONG STRING HERE" )}}`}),}).then(res => res.json()).then(res => console.log(res.data));
Axios
below is a code sample using Axios:
var axios = require("axios").default;var options = {method: 'POST',url: 'https://beta.eu-north.computational-magic.com/api/v1',headers: {'content-type': 'application/json','x-api-key': 'YOUR API KEY HERE'},data: {query: '{summary(input: "YOUR LONG STRING TO SUMMARISE HERE" )}'}};axios.request(options).then(function (response) {console.log(response.data);}).catch(function (error) {console.error(error);});