APIs and Advanced Development Flashcards

1
Q

Q: What is an API?

A

A: An Application Programming Interface (API) allows applications to communicate with each other by defining methods and data structures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: What is the WordPress REST API?

A

A: The WordPress REST API provides endpoints for developers to interact with WordPress sites, enabling data to be accessed and manipulated remotely.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How do you enable the WordPress REST API?

A

A: The REST API is enabled by default in WordPress; you can access it via /wp-json/ on your site.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What is an endpoint in an API?

A

A: An endpoint is a specific URL where an API interacts with data (e.g., /wp-json/wp/v2/posts for retrieving posts).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: What authentication methods are commonly used with the WordPress REST API?

A

A: Basic Authentication, OAuth, Application Passwords, and JWT (JSON Web Tokens).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: How does Basic Authentication work with the REST API?

A

A: It requires a username and password sent in the request header for API access.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: What are Application Passwords in WordPress?

A

A: Application Passwords allow secure API authentication for individual users without sharing actual passwords.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: Why should HTTPS be used when authenticating API requests?

A

A: To ensure secure transmission of credentials and protect against data interception.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What are some default endpoints provided by the WordPress REST API?

A
  • /wp/v2/posts: For retrieving or managing posts.
  • /wp/v2/users: For managing users.
  • /wp/v2/taxonomies: For working with taxonomies.
  • /wp/v2/media: For managing media uploads.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: How do you fetch all posts using the REST API?

A

A: Send a GET request to /wp-json/wp/v2/posts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: How do you create a new post using the REST API?

A

A: Send a POST request to /wp-json/wp/v2/posts with the required data (e.g., title, content) and authentication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What is the difference between GET, POST, PUT, and DELETE in API requests?

A
  • GET: Retrieve data.
  • POST: Create new data.
  • PUT: Update existing data.
  • DELETE: Remove data.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: How do you create a custom REST API endpoint?

A

A: Use the register_rest_route() function in your plugin or theme.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What parameters are required in register_rest_route()?

A

A: The namespace, route, and a callback function to handle the request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: How do you add parameters to a custom REST API endpoint?

A

A: Define args in the route options, specifying parameter types and validation rules.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: How do you restrict access to a custom REST API endpoint?

A

A: Use permission callback functions in register_rest_route() to check user capabilities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Q: What are hooks in WordPress?

A

A: Hooks are functions that allow you to modify or add functionality in WordPress without editing core files. They include actions and filters.

18
Q

Q: What is the difference between an action and a filter?

A
  • Actions: Allow you to add functionality at specific points.
  • Filters: Modify data before it is displayed or processed.
19
Q

Q: How do you register a custom post type?

A

A: Use the register_post_type() function in your theme or plugin.

20
Q

Q: What is a custom taxonomy, and how do you create one?

A

A: Custom taxonomies are used to organize custom post types. Use register_taxonomy() to create them.

21
Q

Q: What is AJAX in WordPress?

A

A: AJAX allows asynchronous communication between the server and client without refreshing the page.

22
Q

Q: How do you enqueue an AJAX script in WordPress?

A

A: Use wp_enqueue_script() and localize it with wp_localize_script() to pass AJAX URLs and data.

23
Q

Q: What is the role of admin-ajax.php in WordPress?

A

A: It processes AJAX requests sent from WordPress themes or plugins.

24
Q

Q: How do you create an AJAX handler in WordPress?

A

A: Add a custom action using add_action(‘wp_ajax_{action}’, ‘callback_function’) and add_action(‘wp_ajax_nopriv_{action}’, ‘callback_function’).

25
Q

Q: What is the WP REST API Schema?

A

A: It defines the structure of API data, including available endpoints, parameters, and response formats.

26
Q

Q: How can you extend existing REST API endpoints?

A

A: Use the register_rest_field() function to add custom fields or modify responses.

27
Q

Q: What is the purpose of REST API filters in WordPress?

A

A: Filters allow developers to modify requests, responses, or behavior of REST API endpoints.

28
Q

Q: How do you handle errors in the WordPress REST API?

A

A: Use the new WP_Error() class to return proper error messages with status codes.

29
Q

Q: What is GraphQL?

A

A: GraphQL is a query language for APIs that allows clients to request only the data they need.

30
Q

Q: What plugin adds GraphQL functionality to WordPress?

A

A: The “WPGraphQL” plugin.

31
Q

Q: What is the main difference between REST API and GraphQL?

A

A: REST APIs return fixed data structures, while GraphQL allows clients to define the structure of the data they need.

32
Q

Q: How do you cache REST API responses in WordPress?

A

A: Use transient APIs or external caching mechanisms like Redis.

33
Q

Q: How can you reduce the performance impact of frequent API calls?

A

A: Implement caching, batch requests, or paginate large datasets.

34
Q

Q: Why should you minimize database queries in custom API endpoints?

A

A: To improve response times and reduce server load.

35
Q

Q: What tools can you use to test REST API endpoints?

A

A: Postman, Insomnia, or the browser’s built-in fetch tool.

36
Q

Q: How do you enable debugging for API requests in WordPress?

A

A: Use the WP_DEBUG constant and log errors using error_log().

37
Q

Q: What WordPress function is used to make HTTP requests in custom API integrations?

A

A: wp_remote_get() for GET requests and wp_remote_post() for POST requests.

38
Q

Q: How do you integrate third-party APIs into WordPress?

A

A: Use HTTP request functions like wp_remote_get() or libraries like Guzzle.

39
Q

Q: What is an API key, and why is it important for third-party API integration?

A

A: An API key is a unique identifier used to authenticate API requests to third-party services.

40
Q

Q: What are webhooks, and how are they used in WordPress?

A

A: Webhooks are automated notifications sent by third-party services to a specific URL in WordPress when certain events occur.

41
Q

Q: What function is used for custom database queries in WordPress?

A

A: The $wpdb object, which allows developers to interact with the WordPress database.

42
Q

Q: How do you protect against SQL injection in custom queries?

A

A: Use prepared statements and the $wpdb->prepare() method.