Where communities thrive

Get a full fake REST API with zero coding in less than 30 seconds (seriously)

People

Repo info

Activity

Darktripe

@Darktripe

One more question. I have a db.json and a routes.json : routes.json reference all routes of my json-server but I have an error when i start my json-server : Range out of order in character class at Regexp (native). My route is this : "/myroutes/reports[001]"

I know that this character "[" and this "]" caused the error but i can't remove this characters rom the request

Can anyone help me please ?

masaanli

@masaanli

Hi how can i make it possible to access /text/get for example?

masaanli

@masaanli

json server Oops, found / character in database property can i make a / work?

Victor Guilherme Santos Hogemann

@vhogemann

hi folks, how can I access the db from a custom route? Or this is only possible from the router.render() method?

Arye Shalev

@pantchox

Hi guys, i love this json-server it saved my life! i wonder if anyone here found a semi automated solution like this with real DB? that create auto routes for _embed and _expand by a structure of you JSON file with real DB such as Mongo or Sqlite? thanks!

André Drougge

@miphe

Hi all

Great mock server, working great for me developing my front-end while the API guys are too slow.

I want to specify a response from the server, when I do a POST. I have a middleware but I can’t really see where I can change the response body in the res.

André Drougge

@miphe

I see there’s an idea about authentication in the docs, however I still have the same issue.

in my isAuthenticated(req) method, I want to check if the request had a certain header (auth token). I keep doing console.log(req) to see where I can find the headers I send.. but to no avail - I can not for the life in me find headers in the request.

req.headers doesn’t show the token that I do send in my req, actually those headers are all different from the ones I send.

André Drougge

@miphe

Don’t really want to mention, but I think this is such a simple thing if you know how to reach it - @typicode perhaps you can shed some light on this.

Now I want to DELETE the foo with id 1. But I don't want to delete the bar. Speaking in terms of SQL I do not want an ON DELETE CASCADE as it looks like it is doning now. In case I DELETE the bar instead I would like the barId property in the foo to either be set to undefined (like with ON DELETE SET NULL) or just removed from the foo object.

Is this possible with json-server today?

Ahmed Ayoub

@Nilegfx

@PerWiklander short answer. No.

Long answer:json-server is an express server so you can do all kind of workarounds you wish.

please let me know if this is not clear so I can find sometime to create an example for you.

Per Wiklander

@PerWiklander

Thanks, I’ll have a look. I guess this is getting close to where the actual server is easier to use than the json mock.

Ahmed Ayoub

@Nilegfx

@PerWiklander not always, most of the time json-server is so useful, its out-of-the-box is more than enough for mocking (not for complex business logic)

Per Wiklander

@PerWiklander

yeah, it has worked well until this problem showed up. I guess I'll just have to create custom routes for the models that do not want to be handled in the ordinary "clean all orphans on delete" way.

Ahmed Ayoub

@Nilegfx

@PerWiklander :+1:

Félix Pelletier

@felpel

is this project still maintained?

it seems that the issues are piling up without any answers :(

typicode

@typicode

Hi @felpel, yes, it's still maintained. Even though I'd love too, I don't have the time to work on all projects and be able to answer to everyone unfortunatly (BTW I'm very thankful to people helping beginners in issues! <3).Also to be able to make significant progress on each projets, I'm rotating between them: hotel got many updates a few months ago, now I'm focusing on husky first v1.0 release and next will probably be JSON Server.To improve this situation, I'm looking at ways to make development more sustainable (Patreon, Open Collective, Sponsoring, other ideas, ...).

Arye Shalev

@pantchox

@typicode thank you so much for JSON server! it saved my life so many times! but then when migrating to a real database, i find it hard to configure all the routes that JSON-server did them automaticlly just by reading the JSON file! do you think there is a way to maybe generate express api endpoints based on JSON file schema as you did for SQL or mongo?

hieyou1

@hieyou1

@typicode How do I set a custom route with Post requests enabled?

@typicode

please

ayazzali

@ayazzali

good project

Pavels Ahmadulins

@Robot1que

@typicode I'm looking for a way to modify (wrap) my responses. I've found examples with .render method but in TypeScript with @types/json-server this method does not exist. What I need to do is convert body of response from object[] to { data: object[], totalCount: header.get('X-Total-Count') }.

Moritz Bust

@Busti

How do I create randomly generated content in a modularized setup with custom rotes?

I am trying to follow the examples, but there is no real link between the index.js example and the server.js example