Get Data for DataTable from an external URL

Hi,
I did not find a tutorial how to fill a datasource by a function that gets the data from an external URL by “4D.HTTPRequest”. Eg. an Entity or an EntitySelection and bind it to WebForm components.

Is there an example how it works, “best practice”?

Hey Renlite

here’s an example we use to get picture from unsplash.com using 4D.HTTPRequest

request=4D.HTTPRequest.new("https://source.unsplash.com/random/100x100?avatar,work").wait()
If (request.response != Null)
	BLOBTOPICTURE(request.response.body; image)
	newUser.pictureProfil=image
end

you can use like this code to fill an entity using an api

var info :object
var newUser: cs.UserEntity
var request : 4D.HTTPRequest
	
request=4D.HTTPRequest.new("yourAPI").wait()
If (request.response != Null)
	newUser=ds.User.new()
	newUser.name=request.response.user.name
	.... 
	newUser.email=request.response.user.email
info=newUser.save()
end

you will find more details about HTTPRequestClass param & return here : HTTPRequest | Qodly Developer Center

1 Like