How to change rest url json extension to base url in Rails4 - json

By default rails sets up the rest routes as:
Get /users.json
/users renders scaffolded views.
I am developing an api application and I dont need scaffolded views.
How can get rid of the views part of an existing application.
And how can I switch the json endpoints to base urls like /users
Any recommendation of an existing gem will be very helpful.

I didn't think rails setup a default for routes? Use you're using it purely as an API.. in which case it might..
You need to setup a folder corresponding to the controller/model which rails looks in. Then it depends on file extension from there.
I can setup .html or .js. or .json .. and the route works accordingly..
OR
Can you not just add respond_to either .js or .html to the controller?
For the scaffold views, you can just delete them from the folder.

Related

using react-router in Next.js environment

I am currently using next.js framework. Is it possible to route components out of /pages directory?
Would not like to use 'react-router' (because it'll be complicated to edit server.js). If it is inevitable I will but is there any other way?
im afraid this is not possible in nextjs. nextjs builds its route view pages folder. what you can do that wont ruin your project structure or URLs is to
add your components to the new repo.
create your pages folder based on your routes in pervious project.
add index.js in each pages folder.
and import the main component instead of actually moving it to pages folder, for example:
export { default } from './components/users';
this way you can drag and drop your existing structure and only add your route as pages folders.
notes to consider:
next default routing is case sensitive so be careful about your folder names if you want a work around for that you should use nextjs v12 create all pages to lower case and config your project to translate all routes to lower case.
you can have nested routes by adding nested folder:
pages
userslist
userdetail
index.js
this structure will create this route:
/userlist/userdetail
if you have components you dont want for user to be accessible do not put them in pages
if you have dynamic routes such as id in your route you can specify it by adding a folder in pages like [id] and redirect to it following this syntax
Router.push(`/sth/sth/${sth.id}`);
this configuration of redirects in nextjs might come in handy when you need to custom your links
i should also warn you migrating an existing project to nextjs requires a lot of work and a lot of changes to the project.

Angular merge multiple JSON files into one

I am trying to configure the i18next framework for translations in my angular app. I would like to have multiple JSON files (one per view or part of application) e.g home, catalogue.
The way I want to approach this is I want to put all of these in the assets folder under translations so the structure will look like this.
-home.json
-catalogue.json
Then eventually when the build runs I want to bundle all of these into a single json file: for example en-GB.json.
The problem I am facing is I don't know how to go about this. I can't locate the webpack config and if I was to introduce one, what would be the impact?
In short how can I bundle multiple JSON files into one file.

How to get list of controller in frontend from backend in Yii2 Advanced Template?

I use metadata class to retrieve data but just only in frontend or backend. i don't know how to get data across from backend to frontend. Thank you very much.
You can use components. It can work for an app (component folder in backend or frontend) or also you can create in common folder, so you could use for both. It's a good way to get maintainable code.
More info: http://www.bsourcecode.com/yiiframework2/how-to-create-custom-component-in-yii2-0-framework/

Add API documentation to website using Swagger document

I have a basic webpage built, and a Swagger document JSON file of my API. I am unsure of how to actually add the data from the document to the website so that it can be browsed.
I want to build hosted documentation for the API.
This is the example given by Swagger: http://petstore.swagger.wordnik.com/#!/pet/addPet
Do I just download Swagger UI and use it in conjunction with the JSON file.
But I am unsure on to achieve this. Any advice on how to go about creating something like this would be very helpful.
Swagger-ui is basically a set of static files you can host on your server to display your API.
Unless you may any major changes, you just need to copy the contents of the /dist folder to your server and host it as part of your application (or static website, doesn't matter).
The SwaggerUi object can be customized to your needs, including the URL of the spec you're hosting.
Keep in mind that if you don't host the ui and spec on the same server, (that is, same host and same port), you need to enable CORS.

Format all model & service URLs to include .json in AngularJS

I'm having a problem where my web service expects all RESTful urls to include a .json extension on the URL. I've made it so in my AngularJS code so that all URLs have that extension. So my service urls look like this:
/resources/:id.json
But the problem is that when I include the .json extension then the POST create restful action ends up posting to a URL that looks like:
/resources/.json
This throws an error.
What I need to do is set the defaults inside my AngularJS app to set .json just before each URL is returned. Any ideas on how to do this?
I don't think so.
You could edit your copy of angular-resource.js to have this. Accept a suffix parameter in your resource or something.
Since this doesn't exist (yet) in AngularJS I had to fork a repo and add it myself.
Here's the repo with this feature added.
https://github.com/yearofmoo/angular.js