I am new to C# and I'm building a Web App. I followed the tutorial on the Microsoft site for building Razor Pages. Now I want to add my own HTML code which makes a request to the GIT API and fetches data. This data I want to add to the MSSQL database.
Is it possible to make an HTTP GET from the web app on localhost to the GIT API? Where do I include the script in visual studio? Including it in any of the index.cshtml or validation.cshtml does not seem to work. Here is what I want to add:
<button id="java" class="btn btn-outline-dark">Java</button>
<button id="ios" class="btn btn-outline-dark">ios</button>
<button id="android" class="btn btn-outline-dark">android</button>
<button id="php" class="btn btn-outline-dark">php</button>
<button id="python" class="btn btn-outline-dark">python</button>
<table></table>
<script type="text/javascript">
var table = $('<table>').addClass('table ');
$('button').on('click', function() {
$.ajax({
headers:{
"Content-Type": "application/json",
"Accept": "application/json"
},
type: 'GET',
url: 'https://api.github.com/search/repositories?q=repos+topic:'+ $(this).attr('id') +'&sort=stars&order=desc&per_page=10',
success: function(data){
table.empty();
table.append("<thead><tr><th>Avatar</th><th>Name</th><th>Score</th><th>URL</th><th>Updated at</th></tr></thead>");
$.each(data.items,function(i,object){
var row = $('<tr>').addClass('table-primary');
row.append('<td><img src='+object.owner.avatar_url+'height=50px width=50px/></td>')
row.append('<td>'+object.name+'</td>'+'<td>'+object.score+'</td>'+'<td>'+object.url+'</td>'+'<td>'+object.updated_at+'</td>');
table.append(row);
});
table.append('</table>');
$('table').replaceWith(table);
}
});
});
</script>
Where do I add the script in my project, how do I put the response I get to the database? I learnt about scaffolding in the tutorials, how do I link my response data to the database methods generated? Please point me in the right direction to learn. Thank you :-)
button