api gateway blocks CORS even when enabled [closed] - ajax

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
trying to call a simple post from my own domain by using jquery ajax
$.ajax({
dataType: "json",
type: "POST",
url: '/api/v1/tenants/all',
data: {
},
success: function (res){
console.log('success')
console.log(res);
drawPlacesOnMap(res.results)
},
error: function (res){
console.log('error')
console.log(res)
alert(res.responseJSON.error)
}
});
getting blocked. the request does not reach the lambda application.
enabled CORS and deployed.
any ideas?

the issue was the / :-)
change url from /api/v1/tenants/all to api/v1/tenants/all

Related

Laravel returns 404 status on all controllers except the root page / [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Сlean laravel and for some reason only returns 200 status on the root page. On other routes, I get a 404 status, and not a specially designed page for a 404 error, but a regular one in which the response sent by the controller is displayed. I can't understand what the problem is, what options could there be?
in routes/web.php
Route::get('/home', function () {
return response('Hello World', 200)
->header('Content-Type', 'text/plain');
});
Route::get('/duck', function () {
return [1, 2, 3];
});
First I would check if all routes are registered. you do that with
php artisan route:list. If not, then enter php artisan route:clear.
If that not helps you can try:
php artisan config:cache
The error was in the nginx configuration the part was missing. If this code is not there, then all routes except the root will be 404. There will also be a problem with route caching, you will need to clear the cache very often after editing routes/web.php
location / {
try_files $uri $uri/ /index.php?$query_string;
}

REST API Security for access only to API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
My spring boot app almost done and one more problem left. I need to implement security part. I wanna make acces to api only by key that will come with request. in URL string, message body or header.It doesnt meter now. I found a lot of different ways, but they use login:password pair, it doesnt interesting for me. Each message have to contain KEY.
It should look like
URL String (Get method)
https://api.domen.com/news/today?key='somekey'&'some filters'
Body (Post method)
https://api.domen.com/news/today?'some filters'
{
"key": "somekey",
...
}
Is there suggestion how use only key and verify it?
I would include the token on HTTP Authorization header with the Bearer schema (instead that using a parameter), it is a good practise
POST /news/today?p=1 HTTP/1.1
Authorization: Bearer 123456
If you want to rely on JTW (again a standard practise) you need to verify the incoming token, this is an example using jsonwebtoken library
Claims claims = Jwts.parser()
.setSigningKey(DatatypeConverter.parseBase64Binary("SECRET"))
.parseClaimsJws(jwt).getBody();
String subject = claims.getBody().getSubject(); // subject in the token
Date date = claims.getBody().getExpiration(); // expiration of the token
This example above assumes that the token (set on the HTTP header) has been signed using the same key "SECRET"
//We will sign our JWT with our ApiKey secret
byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary("SECRET");
Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());
//Let's set the JWT Claims
JwtBuilder builder = Jwts.builder().setId(id)
.setIssuedAt(now)
.setSubject("subj")
.setIssuer("issuer")
.signWith(signatureAlgorithm, signingKey);
Here is a good reference https://developer.okta.com/blog/2018/10/31/jwts-with-java

Why use query strings? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I am making a website using laravel. I have a search page where users can search for products and a SearchController which does the actual searching.
Right now, I am passing the form data to the controller with a post method (search string, filters, etc.), it works brilliantly!
However, I see that almost every website passes the search parameters in the URI using a query string. Why is tht better? Should I be doing the same?
Thanks!
It's good to keep query parameters in uri for SEO purpose. If you use post method, when you refresh page you won't get data. If you use get method, even page is refreshed you will get data. If you pass query in uri, you can directly get the data by accessing that url.
The search parameter in URL is helpful when the user wants to search more item related to that without refreshing the page. You can do it by ajax and php.

BasicHttpEntityEnclosingRequest(String method, String uri) [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 8 years ago.
Improve this question
Can someone help me in getting more information about
BasicHttpEntityEnclosingRequest(String method, String uri).
This did not help me understand the said topic.
What are you trying to do with BasicHttpEntityEnclosingRequest? An entity in httpcomponents refers to the body or the payload of the request.
You should be using sub classes of HttpEntityEnclosingRequestBase that is HttpPut, HttpPost or HttpPatch when sending a HTTP request that has a body.
http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/methods/HttpEntityEnclosingRequestBase.html
You should read the HttpClient Tutorial, particularly chapter 1 to get you started.

ajax basics for beginners [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
$.ajax({
type: "GET",
data: "id="+id+"&id-other="+id-other,
url: "ajax1.php"
}).done(function(data){
$("#div").html(data);
});
I have the code piece above, I search the web but I don't know how to explain what it is for. Is there any tutorials of ajax basics explaining step by step of what
$.ajax() means, what type:Get does, what data:... does etc ?
It is making an ajax (asynchronous) call to a remote page.
type: get
It is a HTTP Get request. The form data will be encoded in the url as query string values.
data: "id="+id+"&id-other="+id-other
This the data being passed to the server page
url: "ajax1.php"
ajax1.php is the server page which handles the ajax request and reponds back,
.done(function(data){
$("#div").html(data);
})
The code which inside the done event will be executed once the ajax call is completed. In this case we will get the response from the ajax call to a variable called data. We are setting that as the innerhtml of some HTML element with an id div.
read this link for more info : http://api.jquery.com/jQuery.ajax/
$.ajax({
type: "GET",
data: "id="+id+"&id-other="+id-other,
url: "ajax1.php"
}).done(function(data){
$("#div").html(data);
Its really simple, we start by declaring AJAX function, then we declare the method(get or post - just like html form), data is used the parameters to be passed through URL. URL is the file which is invoked(just like action in forms). This will invoke your ajax1.php file and return some data, that data is returned in the success function or done function. In your case the data is the data returned from your php file.

Resources