Mock Servers which can support both GraphQL and REST endpoints? - rest

I'm trying to find some mock servers which can support both graphQL and REST endpoints .
so that when I query, it returns back mock data instead of going to the Graphql / Http server.
At the moment I found some ways to mock queries , easygraphql-tester works as a mocker of query or mutation But it specifically for GraphQL endpoints .
Similarly , mock-http-server can be used to mock Http Requests to return specific responses But this is specifically for REST or Http endpoints .
I want to find some way where i can mock both GraphQL and HTTP endpoints at the same time . For Example - if I want to mock queries for GraphQL endpoints i can do that , Also if i want to mock some specific Http Request ,i can do that too using the same tool .
Would appreciate the help if anyone can help me find some mock server to mock both Http and GraphQL endpoints .

Related

How do I write testing within the context of a RESTful JSON API microservice?

Within the context of a RESTful JSON API microservice, what different types of tests would you typically recommend/use, and what is the purpose of each type?
A RESTFul API is nothing but an API that can be invoked on Http.
Just write test cases that you normally write for an API, i.e. mock the data inputs and verify the expectations of individual classes or end to end flow.

URL design for a proxy API

We have multiple API's running for an enterprise. As per our limitation client will allow only one static IP to receive all Inbound/Outbound requests.
So, we need to expose a single API as a bridge between the client system and API's running behind.
How to approach this design?
How to design the URL for this proxy API?
What edge functions does this API need to provide?
Any help would be highly appreciated. Thanks!
You do not need to use web services consumer, yet will need to create a POC.
Define A RAML with required path and RAML, scaffolding should give you API took kit, and connect an HTTP request
use HTTP request
Examples:
Define Headers --- attributes.headers.id etc
queryParams ---- attributes.queryParams.date
if you are sending JSON payload across from ex: postman, change Mime type to application/json
sample http properties for request
http.host=myHost
http.port=8872
http.base.path=/myproxy/services

how to build an application with light-4j that supports both Rest and GraphQL

I am building a new Rest service with several endpoints and also want to support GraphQL endpoint in the same instance, it is possible to do that with Light-4j?
In the handler.yml, you can define two chains of middleware handlers. One for REST endpoints and one for GraphQL endpoints.
Here is one example that has two chains defined.
https://github.com/networknt/light-config-test/blob/master/light-router/local-portal/config/handler.yml
In fact, for all the GraphQL example, there are two Rest endpoints generated from the light-codegen for server info and health check.
Take a look at this example and you can add more Rest endpoints.
https://github.com/networknt/light-example-4j/blob/release/graphql/mutation-idl/src/main/resources/config/handler.yml

Wiremock fake that a service is down

In my current setup, if one of my services is down and a request is made to that service, I send a certain HTTP code in the response.
Now to test this I'm using Wiremock to mock my service. Is there a way to mock that the service is unavailable and return a specific response as a result?
I've tried looking through the Wiremock code but there are barely any comments for the methods. I've also tried looking through the docs and I couldn't find anything about bringing down the service.
you could try ResponseDefinitionBuilder.aResponse().withFault(Fault.CONNECTION_RESET_BY_PEER), ResponseDefinitionBuilder.serviceUnavailable() or simply point your client to a port that is guaranteed to have no listeners, depending on what exactly would you like to test with
service is unavailable and return a specific response as a result

Querying SalesForce DB Records using REST API

I have tried implementing like this to get data from SalesForce DB using the REST api,
uri= ...."/query?q=Select+Acc_Name__c+From+Account__c+where+Acc_ID__c+=+'123456'+Limit+5
HttpGet httpGet = new HttpGet(uri);
This is the syntax i found in here
URI
/vXX.X/query/?q=SOQL query
while this works, I don't really want to expose my query like this in uri, Is there an another efficient way to achieve the same operation using REST api ?
You can't modify the way the REST API works. You can implement your own methods via an Apex Restful Web Service. This would allow you to define a method that receives the querystring via a POST (you could even encrypt it first if you wanted to).
Exposing Apex Classes as RESTful Web Services