Testing the API from the client side [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've been working within a project for a couple of months now and met several issues, when the API response changed by the backend guys and it was structured in a way that I didn't expect it to be structured.
The tests that we have mocks the API responses, so they all pass and there is nothing wrong when deploying the app in that state :(
My question is, as I'm quite new to the testing - is it a common thing to do to test the API responses themselves?
If yes - are there any JavaScript libraries that can help me with that?
If no - how to make sure that the response are structured that way we want them to be?

What you need is to add integration tests to test un-mocked API responses.
AND to prevent unexpected API response structure, you should use a versioned API. So as long as you do not upgrade your API version to a new major version, the API response should not be unexpected.
As you are using Jest you can add your integration test using this framework

You can use the documentation lib like swagger where you can check the structure of the api response.
Refer: https://swagger.io/solutions/api-documentation/

Related

How to use swagger/openAPI on MarkLogic REST APIs for generating documentation? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a bunch of REST APIs (GET/POST methods) written in SJS and I want to use swagger/openAPI for documenting it. I found one GitHub repo with some code but not sure as to how to run/use it with my project.
Link: https://github.com/overstory/marklogic-swagger
PS: My choice of IDE is intelliJ.
Please advise on the steps for the same. Thank you!
I am unaware of tools that can analyze a REST endpoint, and generate Swagger or OpenAPI for it. AFAIK, there are also no tools to generate any such thing from MarkLogic REST extensions or custom MarkLogic REST implementations. It is difficult to write a generic tool that would be able to do so. I am afraid you will have to manually type it, or write some script yourself that is able of generating something useful for your case.
HTH!

What's the best practice for having a Laravel application serve both the browser-based application, and act as an API for the iPhone and Android app? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
We use repository pattern in Laravel 5.1 and kept our logic in repository and we return the data from repo to controller, how can we use same data for Native app and web browser (i.e. web application).....off course data is in json so how can we show same data in blade template...do we need to use another framework for front end (Angular or any other)?
I personally don't think you would need a package or framework to achieve this. Since you are following the repository pattern, your controllers are only in charge of returning results (optionally transforming them for output too).
To achieve your goal;
1- Group your API routes (etc. Route::group('api/v1', ...)
2- Create a class or even better a Trait to detect incoming routes
3- Either within your controller or on the class that handles JSON conversion, detect the route of the request.
4- If the request is being made from the api route, return JSON. Blade template otherwise.
You can also check out this link, which will help you building up your route detection. Also remember that you would need this exact implementation wihin your ExceptionHandler as well. You wouldn't want someone to see a json error message on your web front end, or a 404 blade template being returned from your API.

Information from ICEcast [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a Dutch Radio Station called FinioxFM and I would like to get information from my ICEcast server to my website. I'm using Airtime, I've searched all over the internet and I couldn't find a answer. I saw a lot op options but they were all from 2007 or 2010 and I didn't know if they would still work now. My question is how do I get this information from my ICEcast server. Or is there a simple way with Airtime? Do I use HTML, Java Script or PHP? What are my options?
Using Airtime V2.5.1 and a direct link to my stream is http://radio.finiox.com:8000/live - My website is http://www.finiox.com
Thanks for helping me out!
You're using a rather old version of Icecast, that leads to three options:
Upgrade to latest version (2.4.1) and use the JSON API. (Official packages for many distributions available at http://icecast.org/download/)
Retrofit the JSON API files (status-json.xsl and xml2json.xslt) and put them in your webroot
Write custom XSLT and access that. Some old examples are here: http://ruecker.fi/foss/icecast/xslt/
Please note that both option 2 and 3 mean that you need to do the query and inclusion on the server side. While on Icecast 2.4.1 or newer you also query that data directly from the client web browser, as Icecast supports sending CORS ACAO headers. (See default config and documentation)

Writing an API using bottle/flask to build data visualizations [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to write an API that will read the data fed through a UI, filter the data and feed the data to a set of Javascript (D3) visualizations that I created and output the result as SVG/PNG/PDF.
How am I going to implement this ?
Let me know if more details are required for you to understand and answer the question.
Any help would be highly appreciated.
There is the HTML 5 drag and drop option that is already explained. But if you insist on getting a remote server involved then when you get data through you UI you need to save it in a file or db and then in your back end you clean the data (I assume your cleaning process is happening in Python for example) and then you have a cleaned data ready to be passed. Here you need flask and templates to pass the data to your HTML and evoke D3. If you take a look at Flask quick start then you'll see how flask comes in handy to mediate communication between a backend code and your HTML. From there you get a better idea. I also suggest reading this blog that explains a mini blog application using flask this covers API, Flask part of your question very well.

Testing JavaScript without the codebase [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I know it is a weird question, but wanted clarification nevertheless.
Assume there is an application and the testing team has access to this application only through a URL, with no access to the codebase.
My question is, can one write say jasmine test cases without access to a code base by only using the URL.
PS: My opinion is that it is not possible, because I think it doesn't fit the idea behind which most of these testing frameworks are created.
When accessing the app by URL, does the team have any access to inputs/controls of the app? If so, they can write test cases using something like SilkTest instead. I haven't used Jasmine, but it looks as if it tests actual code itself, rather than doing automated testing on the app as if it were a user. In that case, if your code on the URL is obfuscated or encrypted, then no, they can't test it. If it's plain Javascript code, then they can see it all right in the browser, and write test cases based on that.

Categories

Resources