Wordpress REST API Flashcards

1
Q

Q: What is the WordPress REST API?

A

A: A RESTful interface for interacting with WordPress data using HTTP requests.

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

Q: What does REST stand for?

A

A: Representational State Transfer.

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

Q: What are the primary HTTP methods used in the REST API?

A

A: GET, POST, PUT, DELETE.

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

Q: What is the base URL for the WordPress REST API?

A

A: https://example.com/wp-json/.

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

Q: What is the namespace for core WordPress API endpoints?

A

A: wp/v2.

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

Q: What endpoint retrieves a list of posts?

A

A: /wp-json/wp/v2/posts.

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

Q: What endpoint retrieves a single post by ID?

A

A: /wp-json/wp/v2/posts/{id}.

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

Q: What endpoint retrieves a list of pages?

A

A: /wp-json/wp/v2/pages.

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

Q: What endpoint retrieves all categories?

A

A: /wp-json/wp/v2/categories.

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

Q: What endpoint retrieves all tags?

A

A: /wp-json/wp/v2/tags.

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

Q: What are the common methods for authenticating REST API requests?

A

A: Basic Auth, OAuth, Application Passwords, JWT Authentication.

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

Q: Which authentication method is built into WordPress 5.6+?

A

A: Application Passwords.

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

Q: What header is required for Basic Auth in REST API requests?

A

A: Authorization: Basic [Base64EncodedCredentials].

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

Q: What plugin is commonly used for JWT Authentication?

A

A: The “JWT Authentication for WP REST API” plugin.

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

Q: Why is authentication required for certain REST API actions?

A

A: To ensure only authorised users can create, update, or delete data.

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

Q: What query parameter is used to filter posts by category?

A

A: categories.

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

Q: How can you limit the number of results returned by an API request?
q

A

A: Use the per_page parameter.

18
Q

Q: What parameter is used to paginate results?

A

A: page.

19
Q

Q: How can you search for posts with a specific keyword?

A

A: Use the search parameter.

20
Q

Q: How do you filter posts by author?

A

A: Use the author parameter with the author’s ID.

21
Q

Q: What HTTP method is used to create new posts or pages?

A

A: POST.

22
Q

Q: What HTTP method is used to update existing posts or pages?

A

A: PUT or POST.

23
Q

Q: What is the required header for sending JSON data in REST API requests?

A

A: Content-Type: application/json.

24
Q

Q: How do you specify the post title when creating or updating a post?

A

A: Include title in the JSON payload.

25
Q

Q: How do you set a post’s featured image in the REST API?

A

A: Use the featured_media field with the ID of the media item.

26
Q

Q: What HTTP method is used to delete a post or page?

A

A: DELETE.

27
Q

Q: What parameter is used to force deletion of a post permanently?

A

A: force=true.

28
Q

Q: What is the default behaviour when deleting a post using the REST API?

A

A: The post is moved to the trash.

29
Q

Q: How do you delete a category via the REST API?

A

A: Use the /wp-json/wp/v2/categories/{id} endpoint with the DELETE method.

30
Q

Q: What HTTP status code indicates successful deletion?

A

A: 200 or 204.

31
Q

Q: What function is used to register a custom REST API route?

A

A: register_rest_route().

32
Q

Q: What hook is used to initialise custom REST API routes?

A

A: rest_api_init.

33
Q

Q: What arguments are required for register_rest_route()?

A

A: $namespace, $route, and $args.

34
Q

Q: What is the purpose of the callback argument in a custom route?

A

A: It defines the function to execute when the route is accessed.

35
Q

Q: How do you secure a custom REST API route?

A

A: Use the permission_callback argument to define access rules.

36
Q

Q: Why should you use namespaces for custom routes?

A

A: To avoid conflicts with core or other plugins’ endpoints.

37
Q

Q: Why is it important to validate and sanitise data in the REST API?

A

A: To ensure security and data integrity.

38
Q

Q: How do you debug REST API requests?

A

A: Use tools like Postman, cURL, or the browser console.

39
Q

Q: What header is used to determine the response format?

A

A: Accept: application/json.

40
Q

Q: How can you improve the performance of REST API queries?

A

A: Use caching plugins or transients to reduce database queries.