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

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

Related

Is it possible to create an HTML link to a specific API within a JSON Swagger file?

I have swagger files with URLs like https://gitlab.com//blah/blah/Orders_Swagger.json. I'm building some documentation that links to these files; that works fine. Gitlab renders the page with nice formatting. But some swagger files have dozens of APIs and sometimes I want to reference a specific, critical API, not just send the user to the top of the page.
Swagger UI supports a "deepLinking=true" configuration parameter. It is set to false by support. Gitlab embeds Swagger UI, but does not provide a way to set this parameter, so it is off at the server level.
However, you can enable it by passing a parameter in the URL: &deepLinking=1
Thus, a full, API-specific URL will look like this:
https://gitlab.com/company/blah/blah/Swagger.json?deepLinking=1#/section/targetApiName

AMP-list for email fail to load sample json

I'm new to AMP and I'm a creative designer so my knowledge of front-end backend is limited. I trying to do an AMP email which load info from json and display it in the email.
I'm using sample AMP-list component script from https://amp.dev/documentation/components/amp-list/?format=email, everything work fine but when I replace the json link with my sample file it didn't work https://wegoexperience.com/dest.json
Anyone can advice why? Thanks!
Answer: it's all about CORS, read here: https://amp.dev/documentation/guides-and-tutorials/learn/cors-in-email/
In the sandbox on https://amp.dev/ you won't be able to check your own JSON.
If you have an Apache server, then create(in the folder where the JSON file is located) .htaccess file and write the following code there:
Header add Access-Control-Allow-Origin: "*"
Header add AMP-Access-Control-Allow-Source-Origin: "youaddress#youdomain.com"
Header add Access-Control-Expose-Headers: "AMP-Access-Control-Allow-Source-Origin"
After that, AMP-list should work if you test locally or on your server.

How to retrieve data directly from .json file present on GitHub?

I am developing a Dialogflow chatbot and I found an useful Q/A '.json' file on GitHub. Is it possible to retrieve data directly from GitHub to Dialogflow? if yes, how can I it ?
Maybe, you could try to make a GET request and trying to get a jsonp file.
But chances are, that GitHub doesn't allow CORS (Cross Origin Ressource Sharing).
You can only try it out yourself.
Fetch that file as a raw Github file which will have a similar link like this. https://raw.githubusercontent.com/google-research/bert/master/sample_text.txt

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

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.

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.