How to store and respond with variables for API request - api

I am attempting to create a dynamic responsive server which is able to:
read a request
store the token in an environment variable
use that environment variable in the response back to the source
I am unsure where to begin with this, I have had a look at some API tools such as PostMan and Insomnia but although I can set up a mock server which would receive the responses, the data I want to save is not being stored in the variable and thus is not being used in the response.
Some guidance would be appreciated.
Thank you

What language and platform you are using?
If you are using any of the major public cloud options, (AWS, Google, Azure), there are easy to deploy API Gateway Services that required minimal code to get started and supports environment variables.
If you are using a local development only,
then you can get started with ASP .NET Core Web API: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio
Then use environment variable:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1
Or instead once you setup your API running locally, you can use Postman variables:
https://learning.postman.com/docs/sending-requests/variables/

Related

is there a full Nextcloud API accessable from outside?

I use Nextcloud as a normal user to store and share files.
I decided to use it as a backend for a web application I am developing so that I can store the files in Nextcloud while the frontend is done by me.
I spent some hours on the API docs
https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/index.html
and, with some disappointment, unless I have not made a mistake, I realized that the only API that can be used from outside Nextcloud is the WebDav API.
This is a minimalistic API that allows doing basic things such as uploading a file by passing the full path like with this GET statement (authenticated by basic auth passing username and password in the headers:
GET https://nextcloud.example.com/remote.php/dav/files/username/FolderOne/SubFolderTwo/HelloWorld.txt
This will download the file located in /FolderOne/SubFolderTwo/HelloWorld.txt
with a PUT request, it is possible to overwrite the file by passing the file content in the raw body request
This is very effective but minimalistic.
I was expecting to have a full REST API to access more properties and perform complex operations.
Could you please tell me if I missed some important information?
There is the OCS API but it works only from inside Nextcloud.
Thanks.
A full REST API is avaiable - https://docs.nextcloud.com/server/22/developer_manual/client_apis/OCS/ocs-api-overview.html
Create a Share - https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html
The OwnCloud documentation also offers more examples
https://doc.owncloud.com/server/10.8/developer_manual/core/apis/ocs-share-api.html
You can register an App id and use that to login or passthru a username and password in the authentication header.

FLOWABLE: Authenticating flowable-task from another application via rest call

So, I am creating an application which will be using flowable.
We can say that once my application starts, it's gonna start a particular process deployed on flowable, proceed ahead accordingly.
So, in a way there will be lot of talking between flowable and other application, but for now suppose I just want to call flowable applications from POSTMAN (outside FLOWABLE).
I have used 3 modules: flowable-idm, flowable-modeler, flowable-task in my application.
Everything works fine when I am starting my deployed process from UI of flowable task, problems come when I want to start the processInstance using REST endpoint.
In flowable-task application, there is already a REST endpoint to start the process deployed: http://localhost:8080/flowable-task/app/rest/process-instances.
Now, if I call this from Swagger of flowable-task application, it works fine.
But it doesn't work when I try to call it from another application or POSTMAN for now (once POSTMAN call works, I can make the same arrangement in code), where I'm doing a basic auth and providing what's required in body.
Also, there is no error or exception displayed on console, I believe that is because of something catching that error or exception and not displaying anything.
However, to overcome the problem of starting process from POSTMAN, I can use REST endpoint http://localhost:9999/flowable-task/process-api/runtime/process-instances, but this is just a workaround, in future if I create new endpoints I would have to figure out a way to call those endpoints.
I saw this post and I guess this guy was also trying to achieve something similar but for flowable-modeler.
It's been suggested to make changes in SecurityConfiguration.java of flowable-task-conf module for my case, but I haven't done such changes before so not exactly sure where to start and how to proceed.
So, my question is how to talk to flowable-applications from outside flowable applications.
Edit:
Forum post about getting exception when imported flowable-rest module in workspace
The flowable-task UI Application is an example application that exposes non public REST API for the UI. However, the application also exposes the full REST API of Flowable.
There is also the flowable-rest application that has the Swagger doc and exposes the full REST API without a UI.
You would want to communicate with those REST endpoints.
The endpoints are under the following contexts:
process-api for the Process Engine
cmmn-api for the CMMN Engine
dmn-api for the DMN Engine
idm-api for the IDM Engine
form-api for the Form Engine
content-api for the Content Engine
For your example you would need to use POST to /process-api/runtime/process-instances for Starting a Process Instance

How to set environment variable while posting data to API in Postman

I have few APIs which uses a variable instance with values as dev, test and prod. These values are used in the variable so that the API remains the same and the data can be posted to different environments like dev, test, prod. These APIs are deployed on azure platform
I am using postman to publish data to the API. I have created an environment variable and set its value as dev. I want to know where in the api url I should include this variable in order to successfully send the data.
API Url:
https://ashtechdev.azurewebsites.net/tempdata
I have posted my answer here in this below link. Please use the same.
Hope this helps.

Dynamically controlled swagger / openapi mock server for testing purposes

I'm looking for a project/tool that is able to get swagger / openapi specifications file as a parameter and generate a mock server that can be controlled programmatically via a REST API interface.
For example - if my API contains the following endpoint: "POST /v1/create"
and I have a swagger specs that describe that API, I would like my mock server to be executed in a way similar to:
mock-server -f swagger.yaml -p 8080
While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behavior of the running swagger mock server - i.e: change response code, set response content etc'
I would like to use such mock-server as part of my system-tests suite to better verify my service behavior when interacting with other services - without the need to run those 'real' services.
I'm looking for something similar in spirit to Shopyify's ToxiProxy (https://github.com/Shopify/toxiproxy) but with the above capabilities.
Thanks!
Eldad
I know I'm a bit late to the party on this one, but for future searchers, MockLab now supports auto-generation of mock APIs from an imported Swagger definition and Swaggerhub webhooks.
More details here:
https://www.mocklab.io/blog/mocklab-now-supports-swagger-and-swaggerhub/
I believe Specmatic should help you with this.
mock-server -f swagger.yaml -p 8080
Specmatic works exactly this way. To start a mock server with an OpenAPI specification file we can run below command.
specmatic stub service.yaml --port 8080
Here is the documentation.
While the server runs, It will be possible to interact with it's own REST API (on some control interface via a different port) and change the behaviour of the running swagger mock server - i.e: change response code, set response content etc'
This is also supported. Specmatic has a http interface to which you can post the request and response mappings / expectations. We call this dynamic mocks. Here is the documentation.
Here is a video on this.
Disclosure: I am lead dev and CTO at Specmatic

Invoking wso2greg Artifcat Rest API via wso2api manager is not working - any ideas to fix

UPDATED QUESTION to clarify more.
I have two servers : wso2greg containing custom artefacts and wso2am (api manager).
The gouvernance register is intended to be used internally (intranet) and some of it's feature are intended to be exposed externally and acceded via it's rest API.
In order to manage wso2greg API accesss, we used an wso2am (api manager) server, where we did define an API that act as a proxy for the wso2greg API.
In our experiments, we found the strange behaviour described below :
Successfully direct calling wso2greg artefact rest api (the exact url is
https://localhost:9443/resource/1.0.0/artifact/_system/governance/myartifact/art1 and i'm following the documentation of this REST API from here https://docs.wso2.com/display/Governance520/Resources+with+REST+API ) using postman. The API reacts as described in the documentation.
Error 500, reported on wso2greg server, when calling the same REST API, but via API manager (using publisher application).
So as a summary :
Directly calling wso2greg rest API woks fine and a got results back
Adding this working API, in wso2am and than calling it gives always error 500.
As extra information:
Tested with other wso2greg REST API , such as "rating" or "comments" and I was able to call it successfully either directly or throw Api manager.
Tried to get information related to default wso2greg artifacts such as restservice, but i got exactly the same pb when (error 500) interagting with API manager.
Working with the last version of both products : wso2greg version 5.2.0 and wso2am version 1.10.0
Please advice, or clarify how could i debug this internal error in wso2greg.
Regards,
I hope your not using G-Reg + APIM feature installed version. I presume your using separate G-reg 5.2.0 and APIM x.x.x. Since your using the second option you can't use G-Reg REST API with APIM, therefore you have to use APIM REST API instead.
Get an API
Description: Get details of a specific API.
URI: http://localhost:9763/publisher/site/blocks/listing/ajax/item-list.jag
URI Parameters: action=getAPI&name=xxx&version=xxx&provider=xxx
HTTP Methods: POST
Example:
curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/listing/ajax/item-list.jag -d "action=getAPI&name=PhoneVerification&version=1.0.0&provider=admin"
Please follow this link to see all the api usage.
Thanks #thusharaK for providing help.
The solution was to add Message Mediation Policies which forces json header on output.
Now i got my correct response from API manager (in fact, i got a binary response in test console and a json response in postman) .