json-server / db.json (lowdb) / faker.js in Pharo/Zinc ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

json-server / db.json (lowdb) / faker.js in Pharo/Zinc ?

cedreek
Hi Sven and all,

Disclaimer: just another rather not important query (mainly for fun so don’t hesitate to tell me to use the node packages instead ;-) )

To show API to students, I sometimes use https://jsonplaceholder.typicode.comIt’s nice to play with client requests. I wonder if this would be interesting to have such tools in Pharo/Zn. Maybe it exists already somehow (for Teapot eventually) ? 

From their GitHub, I discovered json-server + lowdb (based on lowdash) => all nodes packages. 


It uses a db file db.json and I like such simple « databases ». I know they're not real db.

To me, it could nearly be to me an elegant personal db even if I think this is mostly used to test API’s. 
Indeed, It’s often used in conjunction with node package faker (https://github.com/marak/Faker.js/ (https://github.com/marak/Faker.js/). 
I would like to use that to generate static websites from Ecstatic.

The placeholder default website has limitations. For instance, the following request creates a new post (but then you cannot see the result if you query for posts just after)



I wanted to go past the limitation of the placeholder site (the db.json cannot be written). I can of course use the node package but you know :)  Might be not so straight to port though.

So there are probably three open questions in this post:
1)  lowdb (I know this is not a database but it’s handy and I’d like such usage in static website generation in conjunction with Ecstatic). Any already existing experiments maybe ? I don’t think Voyage can do that.
2)  the API json-server based on routes (maybe a job for Teapot) ?
3) the faker package as a fun exercice.

What others think ? My priority would go for having some kind of lowdb (and I’m pretty sure there are experiments around that - It reminds me a bit sandstonedb from Ramon http://onsmalltalk.com/sandstonedb-simple-activerecord-style-persistence-in-squeak.

Cheers,

Cédrick



Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-dev] json-server / db.json (lowdb) / faker.js in Pharo/Zinc ?

cedreek
Hi,


Hi Cédrick,

I think making something like jsonplaceholder would be quite easy.

Do you know about the Zinc-REST package/group ?

I knew but forget about it !


It contains an example in its tests, ZnExampleStorageRestServerDelegate with unit tests in ZnExampleStorageRestServerDelegateTest which implements a generic data storage. Have a look !

Will definitely look again at it. Is it using a json file as db too ? I guess that be easy to add if not. I’ll look at it soon.

Any feedback about faker ? That’d be a fun project to do in Pharo.
There are lots of them. I don’t know which one to look at more in detail (js, ruby, python, php... ?).

Anybody knows what’s the most « complete » or elegant ?



BTW, recently I added ZnClient>>#forJsonREST, which uses either STONJSON (which is in the image) or NeoJSON (when loaded), so that you can more elegant code for this use case:


Uhm right, I always forget and use the old way (with #contentReader: ).


Thanks for the information Sven,

Cédrick




ZnClient new
 url: 'https://jsonplaceholder.typicode.com/posts';
 forJsonREST;
 get.

ZnClient new
 url: 'https://jsonplaceholder.typicode.com/posts';
 forJsonREST;
 contents: { #title->'Test'. #body->String loremIpsum } asDictionary;
 post.

Sven

On 6 Jun 2020, at 09:44, Cédrick Béler <[hidden email]> wrote:

Hi Sven and all,

Disclaimer: just another rather not important query (mainly for fun so don’t hesitate to tell me to use the node packages instead ;-) )

To show API to students, I sometimes use https://jsonplaceholder.typicode.com. It’s nice to play with client requests. I wonder if this would be interesting to have such tools in Pharo/Zn. Maybe it exists already somehow (for Teapot eventually) ?
https://medium.com/codingthesmartway-com-blog/create-a-rest-api-with-json-server-36da8680136d

From their GitHub, I discovered json-server + lowdb (based on lowdash) => all nodes packages.
https://github.com/typicode.

<GraphiqueCollé-6.tiff>

It uses a db file db.json and I like such simple « databases ». I know they're not real db.
https://github.com/typicode/lowdb

To me, it could nearly be to me an elegant personal db even if I think this is mostly used to test API’s.
Indeed, It’s often used in conjunction with node package faker (https://github.com/marak/Faker.js/ (https://github.com/marak/Faker.js/).
I would like to use that to generate static websites from Ecstatic.

The placeholder default website has limitations. For instance, the following request creates a new post (but then you cannot see the result if you query for posts just after)

<GraphiqueCollé-5.png>


I wanted to go past the limitation of the placeholder site (the db.json cannot be written). I can of course use the node package but you know :)  Might be not so straight to port though.

So there are probably three open questions in this post:
1)  lowdb (I know this is not a database but it’s handy and I’d like such usage in static website generation in conjunction with Ecstatic). Any already existing experiments maybe ? I don’t think Voyage can do that.
2)  the API json-server based on routes (maybe a job for Teapot) ?
3) the faker package as a fun exercice.

What others think ? My priority would go for having some kind of lowdb (and I’m pretty sure there are experiments around that - It reminds me a bit sandstonedb from Ramon http://onsmalltalk.com/sandstonedb-simple-activerecord-style-persistence-in-squeak.

Cheers,

Cédrick