1. Alessandro Bracco
  2. SnapDevelop
  3. Saturday, 26 December 2020 16:17 PM UTC

Hi All

I'm trying create a REST API based on below video, and getting error like below :

 

(https://www.youtube.com/watch?v=HRKNPA1EM_o&feature=emb_logo)

It could be possibile to dowloand the sample in the video somewhere?

 

Thank you very much

Ale

Alessandro Bracco Accepted Answer Pending Moderation
  1. Thursday, 25 February 2021 09:58 AM UTC
  2. SnapDevelop
  3. # 1

Hi Marco, sorry for late reply i saw only now your suggestion.
I apply your code and it's seems work better, the error disappear but I do not see any value . The data seems to be retrive correctly because i see page (1-5 of 14) but i don't see any data, any idea about that?

 

 

Comment
  1. Alessandro Bracco
  2. Thursday, 25 February 2021 14:55 PM UTC
I fix it, it was a field name wrong, Thanks again Marco!
  1. Helpful
There are no comments made yet.
Alessandro Bracco Accepted Answer Pending Moderation
  1. Monday, 28 December 2020 16:31 PM UTC
  2. SnapDevelop
  3. # 2

Hi Marco

It seem very different from your screenshot, "CONNECTION REFUSED" , am I miss something!?

 

 

Thanks again

Ale

 

 

 

Comment
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Monday, 28 December 2020 16:14 PM UTC
  2. SnapDevelop
  3. # 3

Hi,

you should be able to fetch data using this code

async mounted () {
    const response = await fetch(FETCH_VEM_URL, {
      method: 'GET',
      headers: {
        'Content-type': 'application/json'
      }
    })
    this.items = await response.json()
  }

Please debug from Chrome: select Dev tools -> Network and check in the console how the client request is formed, including headers.

 

Best,
.m
Comment
  1. Alessandro Bracco
  2. Thursday, 31 December 2020 08:28 AM UTC
Thanks a lot Marco any idea related to the 'CONNECTION REFUSED' in Chrome debug window?
  1. Helpful
  1. Marco Meoni
  2. Thursday, 31 December 2020 10:50 AM UTC
I see think it has to do with CORS, you need to disable it for browser-based clients because API requests started from JS (an application) and not from the browser. In the API project you need to add:



public void ConfigureServices(IServiceCollection services)

{

services.AddCors(options =>

{

options.AddPolicy("CorsPolicy",

builder => builder

.SetIsOriginAllowed((host) => true)

.AllowAnyMethod()

.AllowAnyHeader()

.AllowCredentials());

});



and



public void Configure(IApplicationBuilder app, IHostingEnvironment env)

{

app.UseCors("CorsPolicy");



Best,

.m
  1. Helpful
There are no comments made yet.
Alessandro Bracco Accepted Answer Pending Moderation
  1. Sunday, 27 December 2020 19:12 PM UTC
  2. SnapDevelop
  3. # 4

Hi Marco

First of all thanks for your help, I followed step by step your very interesting demo!

Below some screenshot that can help to better understand my issue. When I run the Rest API from SnapDev it works fine, data retrive correctly, but when i Run the Quasar I saw in the console the error 405.