eduardoboucas / static-api-generator Goto Github PK
View Code? Open in Web Editor NEW๐ง Generate a static JSON API from a tree of directories and files
Home Page: https://www.npmjs.com/package/static-api-generator
๐ง Generate a static JSON API from a tree of directories and files
Home Page: https://www.npmjs.com/package/static-api-generator
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.
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.
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
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
}
}
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
?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.