GithubHelp home page GithubHelp logo

eduardoboucas / static-api-generator Goto Github PK

View Code? Open in Web Editor NEW
147.0 2.0 9.0 127 KB

๐Ÿ”ง Generate a static JSON API from a tree of directories and files

Home Page: https://www.npmjs.com/package/static-api-generator

JavaScript 100.00%
api static json-api

static-api-generator's People

Contributors

eduardoboucas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

static-api-generator's Issues

static-api-generator generates .json

First of all, thx for your greate tool. I'm playing arround with it and have a issue that i couldn't solve.

I read the article from CSS Tricks.

I create a source folder with the following structure:

source
    slogan1.yaml
    slogan2.yaml

the structure of slogan is only
author: "Hugo"
slogan: "Lorem ipsum ..."

I want to generate the following endpoint
/slogans

The Code of my server.js:

    const API = require('static-api-generator')
    const slogansAPI = new API({
        blueprint: 'source/:slogan',
        outputPath: 'output'
    })

    slogansAPI.generate({
        endpoints: ['slogans'],
    })

After generating it with npm start I get 2 json files

  • .json
  • slogans.json

Can you tell me what I'm doing wrong. The strange thing ist the content of slogans.json. It contains two result objects?

The content of .json seems right, but why is there no filename?

Content of slogans.json

    {
        "results": [
            {
                "results": [
                    {
                        "undefined_id": "10c8f19f2d98c3eb66ec911b5dc5abd0",
                        "author": "Hugo",
                        "title": "Lorem ipsum"
                    },
                    {
                        "undefined_id": "dfbdfa8f69d0b629153207a17e565fd9",
                        "author": "Hugo",
                        "slogan": "Lorem ipsum dolor"
                    }
                ]
            }
         ],
        "metadata": {
            "itemsPerPage": 10,
            "pages": 1
        }
    }

Content of .json

    {
        "results": [
            {
                "undefined_id": "10c8f19f2d98c3eb66ec911b5dc5abd0",
                "author": "Hugo",
                "title": "Lorem ipsum"
            },
            {
                "undefined_id": "dfbdfa8f69d0b629153207a17e565fd9",
                "author": "Hugo",
                "slogan": "Lorem ipsum dolor"
            }
        ],
            "metadata": {
            "itemsPerPage": 10,
            "pages": 1
        }
    }    

Project Dead?

Is this project dead? I tried running through the instructions and building a basic one using the example from the blog post, but i was getting lots of errors and it never actually generated any json :(
any alternatives or new versions of this?

Add warning / error when something else than YAML is passed

I wanted to try the generator API so I installed it: npm i static-api-generator

I created a generator for my JSON data:

const API = require('static-api-generator');
const api = new API({
    addIdToFiles: true,
    blueprint: 'data/:page/:category',
    outputPath: 'temp/api/',
    pluralise: false
});
api.generate({
    endpoints: ['page', 'category']
});

then run it: node script.js.

And the result is that I have one char per entry:

And if I put addIdToFiles to false I have the whole content as one string

So it's like newline terminator are not properly detected.

I'm running it under archlinux with LN (\n) as final newline and utf-8 as charset. And I'm using node v10.0.0. All data files are JSON.

Endpoint for fields

Hi @eduardoboucas

First of all thanks for your great tool.

By reading the README I saw the sort parameter is able to sort entries by a field (that is inside the data files). All of this is very well but I was worried about a point.

Tell me if it is just a question or if it is a feature request: I wanted to know if it is possible to generate endpoint for fields (that are inside data files).

To keep you example you are able to generate endpoint for language, genre, year, movie. But if data files (yaml or JSON) are containing a structure like:

    {
      "budget": 10000000,
      "directors": [...],
      "writers": [...],
      "stars": [...]
    }

Would it be possible to generate endpoints for budget, directors, writers, stars ?

Searching

Using the example on the README.md file would it be possible to write an endpoint that searches based on a partial string? For instance could I query like /english/action/action?name=dea and get returned the deadpool movie. I had the idea to do something like this a while back and I couldn't get past this hang up. Thanks in advance for any insight you can provide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.