Skip to content

laserchicken/wordnet-graphql-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wordnet graphql express.js api, because why not? It utilizes wordpos package.

Example client

const axios = require("axios");

const query = `{
  getWordnet{
    getPos(text: "The angry bear chased the frightened little squirrel.") {
      nouns
      verbs
      adjectives
      adverbs
    }
    lookup(word: "bear") {
      gloss
      synonyms
      def
      exp
      pos
    }
  }
}`;

axios({
  url: "http://localhost:4000/wordnet",
  method: "post",
  headers: {
    "Content-Type": "application/json",
  },
  data: { query },
}).then((result) => {
  console.log(result.data);
}).catch((data) => {
  console.log(data.response.data);
});

In production add Authentication and Date headers:

const time = Date.now().toString();

const authHeader = () => {
  const hmac = crypto.createHmac("sha256", "secret");

  hmac.update(time);
  hmac.update("POST");
  hmac.update("/wordnet");

  const contentHash = crypto.createHash("md5");
  contentHash.update(JSON.stringify({ query }));
  hmac.update(contentHash.digest("hex"));

  return `HMAC ${time}:${hmac.digest("hex")}`;
};

axios({
  url: "http://localhost:4000/wordnet",
  method: "post",
  headers: {
    "Content-Type": "application/json",
    Authentication: authHeader(),
    Date: time,
  },
  data: { query },
}).then((result) => {
  console.log(result.data);
})

Releases

No releases published

Packages

No packages published