I'm trying to use the cfs:http-publish package at https://github.com/CollectionFS/Meteor-http-publish. While I've got the GET - /api/list functionality working, I don't know how to obtain a single document:
(GET - /api/list/:id - find one published document).
Can someone provide a curl example of this, assuming a certain collection of objections.
eg: {a:3, b:2}, {a:4, b:3}, and requiring to obtain the object with {a:3}.
Thanks.
You need to put it in the query function.
HTTP.publish({collection: myList},function( ){
return myList.find(this.query);
});
this.query contains the data you sent with your request.
curl http://localhost:3000/api/myList?a=3
I don't know enough about mongo to know if this is a potential security risk, if anyone can comment on that please do.
Related
I have nextjs app with sentry. I want to add new api route, for example api/status, but I want to exclude it from being sent to sentry as it will clutter logs really fast and use my qouta.
I did a small research and it seems that there is an array of urls you can exclude from being tracked. It's called denyUrls. Read more. I have tried to add my url to this array, but it still tracks this url as part of events:
Sentry.init({
...
denyUrls: [
/api\/status/i,
],
...
});
Am I configuring something wrong or this array is not for the purpose of filtering everts.
If so, what's the best way to filter those? Other option I found which I will try next is beforeSend but it feels a bit overkill to simply exclude url. denyUrls feels like much better fit for what I am trying to achieve
I had the same issue and contacted the support for it. I am directly quoting the support here.
The BeforeSend and DenyUrl are options to filter error events, not transactions. For transaction events, please use the tracesSampler function as described on the page: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/sampling/#setting-a-sampling-function.
Here is an example to drop all transactions that match a certain name:
tracesSampler: samplingContext => {
if(samplingContext.transactionContext.name == "GET /api/health"){
return 0.0 // never send transactions with name GET /api/health
}
return 0.2 // sampling for all other transactions
}
Note that you might need to customise the function above to better match your scenario.
I hope it will help you ;)
Have a nice day.
I am trying to get data from Firestore in a batch using the batchGet method. But i get an error as below :
Error: JSON error response from server: [{"error":{"code":400,"message":"Document name "["projects/MYPROJECT/databases/(default)/documents/MYCOLLECTION/DOCUMENTID"]" lacks "projects" at index 0.","status":"INVALID_ARGUMENT"}}].status: 400
I have searched for any questions regarding this, I found this. They are trying t add documents and not using batchGet, however I have followed the solution. Still no luck.
Note: I am integrating Firebase to AppGyver.
I am new to Firebase and still learning. I need all the help I can get. Thank you in advance.
I have found what I did wrong.
In AppGyver you can only set your parameters as text or number only. While the documents parameter needs to be in array. Hence, I convert the array to string using ENCODE_JSON. But that was wrong.
The correct way is just send the documents in array without converting it. Use the formula :
Just hit "Save" even there is an error telling you that it is not a text.
I am trying to make some further adjustments to an address text field. But the problem is that its made with airtable. I want to get the input of that address and use it to get some data from zillow API for the user. How can I do this? I have viewed the source HTML and I only see the airtable script.
This probably went unanswered for being too vague. I'll try to leave some pointers if anyone stumbles upon this in the future.
Are you the host of the WP page? do you have access to the Airtable base in question? Is the "frontend" viewable? Airtable's API is pretty well-documented, simple as it may be. Whatever you need, if it's from a shared view, it can be fetched with a curl request.
Other than that,if the base is public, or shared publicly, and particularly if you need this data at a steady rate or in larger quantities, you'd be better off requesting access and collecting the information with a script from the Scripting app. Since ES6, this is as trivial as doing something like
let query = await base.getTable
(cursor.activeTableId)
.selectRecordsAsync()
let payload, selectAll = query.records.map(rec => rec.name),
selectAll ?
payload = { records: JSON.stringify(selectAll) }
: console.error('something went wrong')
remoteFetchAsync(('your scraping endpoint', payload)=>
//rock'n'roll past this point
})
I have written several tests in Postman, based on the example snippet codes given in the Postman GUI on Windows desktop.
Mainly, I want to check for existence of the parameters in the response (exact in those cases where I need to check for particular values of the parameters) and I want to know if there's a better way to do it than the way I've been doing now.
The following test shows one such example and this is just a small part of it. The actual response schema is a lot larger so I envisioned writing 50-60 lines of such checks per API endpoint.
pm.test("Det details of a POI", function () {
pm.expect(jsonData.code).to.eql(0);
pm.expect(jsonData.data[0].provider).to.eql("google");
pm.expect(jsonData.data[0]).to.have.property("id");
pm.expect(jsonData.data[0].location).to.have.property("position");
pm.expect(jsonData.data[0].location.address).to.have.property("text");
pm.expect(jsonData.data[0].location.address).to.have.property("house");
pm.expect(jsonData.data[0].location.address).to.have.property("street");
pm.expect(jsonData.data[0].location.address).to.have.property("postalCode");
pm.expect(jsonData.data[0].location.address).to.have.property("city");
pm.expect(jsonData.data[0].location.address).to.have.property("county");
pm.expect(jsonData.data[0].location.address).to.have.property("state");
pm.expect(jsonData.data[0].location.address.country).to.eql("United Kingdom");
pm.expect(jsonData.data[0].location.address).to.have.property("countryCode");
pm.expect(jsonData.data[0].contacts).to.have.property("phone");
pm.expect(jsonData.data[0].contacts.website.value).to.include("www.google.com");
pm.expect(jsonData.data[0].contacts.website).to.have.property("label");
pm.expect(jsonData.data[0].categories[0]).to.have.property("id");
pm.expect(jsonData.data[0].categories[0]).to.have.property("title");
pm.expect(jsonData.data[0].categories[0]).to.have.property("type");
pm.expect(jsonData.data[0].categories[0]).to.have.property("system");
)};
Any tips and improvements would be greatly appreciated.
You're basically asking the same as these two Stack Overflow posts:
Schema validation using Postman
How to validate response in Postman?
Answer: There is a json format validation build into Postman it uses the Tiny Validator project to allow schema validation in post-request test scripts. Research Postman's documentation (1, 2) for examples on how to use it.
Whenever I encounter code snippets on the web, I see something like
Meteor.subscribe('posts', 'bob-smith');
The client can then display all posts of "bob-smith".
The subscription returns several documents.
What I need, in contrast, is a single-document subscription in order to show an article's body field. I would like to filter by (article) id:
Meteor.subscribe('articles', articleId);
But I got suspicious when I searched the web for similar examples: I cannot find even one single-document subscription example.
What is the reason for that? Why does nobody use single-document subscriptions?
Oh but people do!
This is not against any best practice that I know of.
For example, here is a code sample from the github repository of Telescope where you can see a publication for retrieving a single user based on his or her id.
Here is another one for retrieving a single post, and here is the subscription for it.
It is actually sane to subscribe only to the data that you need at a given moment in your app. If you are writing a single post page, you should make a single post publication/subscription for it, such as:
Meteor.publish('singleArticle', function (articleId) {
return Articles.find({_id: articleId});
});
// Then, from an iron-router route for example:
Meteor.subscribe('singleArticle', this.params.articleId);
A common pattern that uses a single document subscription is a parameterized route, ex: /posts/:_id - you'll see these in many iron:router answers here.