Using Graphql and Github API to get repository information - javascript

I’m new to web development and I’m trying to make a portfolio website for myself. At the moment I’m trying to stay as vanilla as possible. On my homepage I want to grab information from the repository that I last committed to, title, description, commit history, etc. So that anyone who visits my site can see my latest project.
I’ve learned that you can use graphql to interact with the github API to grab this information, and that you can use a simple HTTP request in JavaScript using the fetch function to send a query. My confusion comes in when you start involving authentication tokens and once I have one how to keep it private instead of hard coding it into my website code.
If anyone can explain, it’d be much appreciated

If you confused about how to do that, I suggest taking a look at the example at https://graphql.org/graphql-js/passing-arguments/
If you want to try the GraphQL queries/mutations out yourself, you can try at https://developer.github.com/v4/explorer/
Without knowing what you already tried this is all I can offer.

Related

How to connect Next.js to Database?

I want to make an application "like" Samsung Health that will use massively queries on a Database.
I would like to know if is better create a custom server made in Node.js (using Express.js) rather than use the integrated one in Next. On Next documentation seems to be some differences.
Where I can find other documentation? On Next documentation I didn't find anything that tell me how to proceed.
I solve it. I had to use fetch function and pay attention with the promise. I had to take the body of the post request and tranform it into json file. Obviously it's necessary that both backend and frontend are currently running.

I can’t get Contentful connected to my site

So, I've only ever used WordPress, but I decided to build my site from scratch so I'm free to do whatever I want with my site. I'm a new developer and I just heard about Contentful.
I like the sound of it and I want to use it to build my blog, but I've been following their instructions and looking up external tutorials for 8 hours and I can't get it to work.
Contentful recommends using cURL, but I don't understand where to put that code or how to tell my site to generate a new page for every blog post once it's there. I've also tried the JavaScript instructions and that failed. There are like 6 other language options on Contentful, but I'm not familiar with any of them.
Sorry for my ignorance, I'd love any insight (and especially explicit instructions) you can give me on the best way to set up Contentful to semi-automatically push blog posts to my blog page.
Thanks!
With Contentful, you can use any front-end framework of your choice. Contentful will help you with managing your content, and you have the flexibility to select the language and framework you want to use for your front end.
If you want to quickly get started and are already familiar with the React ecosystem, you should check out Next.js or Gatsby quick start guides.

is it possible to built REST API without knowing about frontend for mobiles apps

This could be a silly question but I want to confirm about it. I am a backend Laravel developer and have created my website. Now I want to create mobile mobile apps but have no knowledge of front-end.
Due to lockdown situations I want to use this time to create the backend API for my apps. Now I want to know is it ok or a normal practice to create APIs without knowing anything about front end. (Like is it possible that I just create all the endpoints now that are throwing data in JSON and then the front-end developer will use them to integrate in the front-end? Thanks
P.S: I dont know how the app front-end will look like but I know what data will be needed in each page/view.
I think you can do this easily with graphql.
A Frontend dev and also beginners with Apollo in the frontend can easily introspect and build the stuff.
If you can choose your Frontend stack there is no problem with rest either.
I always do the Frontend first approach.
Mocking the data for graphql types and building the api later seems to me the best workflow ever.
See ya. Much fun with your project
Yes it is possible very possible to do that it would be nice is the API is well documented using postman or swagger for a better experience when frontend engineers want to integrate
Many API's in the world today are never consumed by a browser or app on the frontend, sure it can make life easier knowing why you are building it.
But at the end of the day, a good API is simple and easy to understand. It just allows a developer to fetch data from a system but normally with some idea about each type of request.
For example, if you had an API for a university the endpoints could be as follows:
/pupils => Get/Sets pupil data.
/teachers => Get/Sets teacher data.
/classes => Get/Sets class subjects and references ID's of both Pupils and Teachers.
So if you wanted all the Pupils in a given class you would query the /classes endpoint and then for each Pupil ID you would query the /pupil endpoint.
Sometimes not having a frontend makes the API even more generic because you might think differently when you do not have a frontend.

Creating a node.js server on Azure that will allow AJAX calls from Javascript on the client

I've created a webapp where most of the processing is done by the users browser using Javascript. For it's development I've used locally stored JSON docs but I need to be able store these in an Azure Cosmos DB.
I'm struggling to understand how to create an Azure function where I can do AJAX calls to the function, which is then passed on to the DB. I've been playing with node.js and express but how do you link DocumentDB module and expose that to another module that can provide AJAX requests?
I've tried looking through Microsofts examples but they are huge, pulling in loads of modules and trying to reverse engineer them and understand how they work is almost impossible for a newbie like me. Can any point in the right direction? Happy to learn and read up but I've not found anything on Google despite spending all day looking.
More research (and coffee) today. The way I've figured this out is follow this SkillShare course
Using the code function in Postman (set to JavaScript XHR) will give you the AJAX calls and following the link Marc gave in the comments to my question will allow you to swap the Mongoose package for the DocumentDB package. Then it's just a case of writing functions and a user interface around this.
I'm going to start by building a user interface page for the courses CRUD app as a prototype before looking to translate this to DocumentDB.

Wordpress to other source rest calls with username / password

I have been asked to create some custom content on a wordpress site, basically just some web app stuff (html/css/js), but leveraging data from another source via restcalls. There is a service account un/pwd required, and I am wondering what is best practice/approach in terms of the cross site calls with this un? The wire is encrypted but I certainly don't want to store the creds on the client (wordpress admin stuff). I am assuming there is a mechanism to store such on the 'back-end', filesystem, but I am not even sure such access exists? How you get to this....I have gone through the wordpress admin board and haven't found anything that provides access to the filesystem/php files, etc. Perhaps I am not looking in the right place or after the wrong bits?
I have googled but am such a noob with wordpress I am not even sure I have the right approach in mind; any help/advice is greatly appreciated.
EDIT: so if curl is the standard approach for this type of thing, where/how am I able to access the filesystem/php? Is there a specific place this type if thing lives or a convention of where it is placed? Just help with some 101 direction please.
First things first, you will need to develop a plugin for WordPress to properly hook into everything and play nice with everyone else. There are many tutorials for getting started. Here's one that integrates with an API
If you have to store things to make your plugin integrate with this third party, you should use the Options API that WP provides to you, with the information set from a settings page. Please don't hardcode that into a file somewhere in the code. (I'll also mention if you need something more powerful than the plugin options, you can add custom tables)
Now we have code running on WordPress with the information it needs, now it needs to do something. To pull the information from this third party, we can use PHP cURL.
Last, depending on how we want this information to end up being consumed by the user. We can do something simply such as just fetching/injecting the data during a regular WP page load on our custom page. Or we could be fancier and set up a WP REST API endpoint that re-serves the information we got from the 3rd party. Shortcodes? Widgets? Custom Templates? Filter Hooks? There is a lot of ways to present our final interface to the user.

Categories