In Angular PWA How to Cache the API request( with paramter ) dynamically instead of manually adding each and every url in ngsw-config.json - api

I have some API like https://api-******y?apikey=sX4&q=london, Where q=london is a parameter that will keep changing, So how can i add this URL in the list of urls in ngsw-config.json file
"dataGroups": [
{
"name": "api-performance",
"urls": [
"https://api-***************y?apikey=sX******4&q=london",
"https://api-***************y?apikey=sX******4&q=manchester",
"https://api-***************y?apikey=sX******4&q=birmingham"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
},
I have two doubts:
Instead of adding same url again and again for all different parameters like london/manchester/birmingham is there a way that i can just add the base URL without parameter and it will store the responses for all different parameters when user will search for it?
Instead of adding the URL's manually, the URL's response should be stored dynamically when the user has searched for it when he was online. I mean i will initially not add any URL in list in the ngsw-config.json file, BUT when user has requested for that url, its response automatically get stored in cache.

I got this one, Its actually a little stupid of me to think that i have to give the complete url in the ngsw-config.json file,
Actually we just can simply give the base url, we neither have to give the apiKey parameter nor any other parameter like london/manchester/birmingham, ngsw.json file in dist folder after the build, stores the url as patterns, it just matches the base url and stores all the queries with all different parameters made to that url by user. above code can re-written like below. it will work fine by caching the data for all the stores london/manchester/birmingham, whenever user searches for them.
"dataGroups": [
{
"name": "api-performance",
"urls": [
"https://api-***************y
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
},

Related

Template message in whatsapp with static url

I am using whatsapp cloud api for messaging. I have created a template with a url button. In the template I have used a link to my app(Google play store). As per documentation,
https://developers.facebook.com/docs/whatsapp/on-premises/reference/messages#template-object
Developer provided suffix that will be appended to a previously created dynamic URL button.
I do not have any suffix as it is not a dynamic link. If I create a blank text parameter as sufix, Postman responds with error. How to create a url button without any suffix or please let me know if there is any other workaround for this issue. I do not want to add url directly into the body
{
"type": "button",
"sub_type": "url",
"index": "0",
"parameters": [
{
"type": "text",
"text": ""
}
]
}

How to POST json parameters from Postman to Jenkins?

I need to call a Jenkins job using its API through Postman. This job requires parameters (HOST, VERBOSITY and PMSP).
Auth works using Jenkins token and header Content-type:application/json is used.
I tried to call the endpoint https://jenkins_server/job/job_name/build/api/json adding the following body to the request but the result is Nothing is submitted, and the job doesn't run.
I tried to call the endpoint https://jenkins_server/job/job_name/buildWithParameters/api/json adding the same body. I get 201 Created (job is running) but no parameters are given to the job.
{
"parameter": [
{
"name": "HOSTS",
"value": "[linux]\n1.2.3.4"
},
{
"name": "VERBOSITY",
"value": "vv"
},
{
"name": "SANS_PMSP",
"value": true
}
]
}
Is my JSON well constructed ? Which endpoint do I need to call ?
If it's Postman that you would like to focus on, you can import the curl command straight into the application.
This creates a new request for you to use and it populates this request, based on the details in the command.
From here, you should be able to add your own URL and point this at the location you need.

How i get collection metafields using shopify api

I am working on shopify private app . During some task adding some meta fields using shopify api method:
Add a metafield to an existing collection
PUT /admin/custom_collections/#{id}.json
{
"custom_collection": {
"id": 841564295,
"metafields": [
{
"key": "new",
"value": "newvalue",
"value_type": "string",
"namespace": "global"
}
]
}
}
==========================================
next i need to get all collection meta fields but i did't found any solution.
Any resource in Shopify provides a method to get the Metafield resources attached to them. So given that you have a collection ID, think along these lines:
/custom_collections/:id/metafields.json
...to get the Metafields resources using RestAPI. Beware the fact that you might only get 50 of the resources since that is an internal limit. You can get more when you page through the resources and provide a limit. With paging, you can get all the resources, up to 250 Metafields per call.
Note that there are other ways to do this too, using mutations with the GraphQL library for example.

apache nutch to index to solr via REST

newbie in apache nutch - writing a client to use it via REST.
succeed in all the steps (INJECT, FETCH...) - in the last step - when trying to index to solr - it fails to pass the parameter.
The Request (I formatted it in some website)
{
"args": {
"batch": "1463743197862",
"crawlId": "sample-crawl-01",
"solr.server.url": "http:\/\/x.x.x.x:8081\/solr\/"
},
"confId": "default",
"type": "INDEX",
"crawlId": "sample-crawl-01"
}
The Nutch logs:
java.lang.Exception: java.lang.RuntimeException: Missing SOLR URL. Should be set via -D solr.server.url
SOLRIndexWriter
solr.server.url : URL of the SOLR instance (mandatory)
solr.commit.size : buffer size when sending to SOLR (default 1000)
solr.mapping.file : name of the mapping file for fields (default solrindex-mapping.xml)
solr.auth : use authentication (default false)
solr.auth.username : username for authentication
solr.auth.password : password for authentication
at org.apache.hadoop.mapred.LocalJobRunner$Job.runTasks(LocalJobRunner.java:462)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:522)
Was that implemented? the param passing to solr plugin?
You need to create/update a configuration using the /config/create/ endpoint, with a POST request and a payload similar to:
{
"configId":"solr-config",
"force":"true",
"params":{"solr.server.url":"http://127.0.0.1:8983/solr/"}
}
In this case I'm creating a new configuration and specifying the solr.server.url parameter. You can verify this is working with a GET request to /config/solr-config (solr-config is the previously specified configId), the output should contain all the default parameters see https://gist.github.com/jorgelbg/689b1d66d116fa55a1ee14d7193d71b4 for an example/default output. If everything worked fine in the returned JSON you should see the solr.server.url option with the desired value https://gist.github.com/jorgelbg/689b1d66d116fa55a1ee14d7193d71b4#file-nutch-solr-config-json-L464.
After this just hit the /job/create endpoint to create a new INDEX Job, the payload should be something like:
{
"type":"INDEX",
"confId":"solr-config",
"crawlId":"crawl01",
"args": {}
}
The idea is that need to you pass the configId that you created with the solr.server.url specified along with the crawlId and other args. This should return something similar to:
{
"id": "crawl01-solr-config-INDEX-1252914231",
"type": "INDEX",
"confId": "solr-config",
"args": {},
"result": null,
"state": "RUNNING",
"msg": "OK",
"crawlId": "crawl01"
}
Bottom line you need to create a new configuration with the solr.server.url setted instead of specifying it through the args key in the JSON payload.

How to send pushes with "conditions" to pushwoosh with remote API?

I use the pushwoosh remote API and I can send pushes to all users and to just one device, good!
But now Im trying to be able to send pushes to different groups and Im trying to get "conditions" to work. But Im missing something and I don´t know what!
I have first created a tag called "Grupper" as a listtag at pushwoosh.
And it is registering the value "5A" at pushwoosh from the app.
And this is how I try to send a push from my server.
var tags="5A"
var data = {
"request": {
"application": applicationId,
"auth": authKey,
"notifications": [{
"send_date": "now",
"ignore_user_timezone": true,
"content": {
"en": pushtext
},
"conditions":["Grupper", "EQ", tags]
}]
}
};
And here its the "conditions" that is wrong somehow?
If I remove the row with "conditions" then it sends a push to all users, but if I use it, it sends nothing. No errors.
Any input really appreciated, after a couple of days trying, I still don´t know what Im missing :-)
A condition is always an array of arrays, therefore try this:
"conditions":[["Grupper", "EQ", tags]]
Also, since "Grupper" is a List-type tag, you can only use IN operator with it (see the docs here)